Using clang-tidy to fix compiler errors

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
Hello,

clang-tidy can not only be used to improve code, but also to make it work in
the first place.

Taking an example from
https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dependent
-template-recover.cpp

    template<typename T, typename U, int N>
    struct X {
      void f(T* t) {
        t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
as a dependent template name}}
      }
    };

Clang-tidy is capable of fixing that error.
However it's not possible to fix it without running any other checks?!
e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors
but it performs all sorts of other changes.

The best approach seems to be to pick some checker that doesn't find
anything in order to fix only errors ?!

Thanks,
Alexander Lanin


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
On 21/10/2019 23:59, Alexander Lanin via cfe-dev wrote:

> Hello,
>
> clang-tidy can not only be used to improve code, but also to make it work in
> the first place.
>
> Taking an example from
> https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dependent
> -template-recover.cpp
>
>      template<typename T, typename U, int N>
>      struct X {
>        void f(T* t) {
>          t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
> as a dependent template name}}
>        }
>      };
>
> Clang-tidy is capable of fixing that error.
> However it's not possible to fix it without running any other checks?!
> e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors
> but it performs all sorts of other changes.
>
> The best approach seems to be to pick some checker that doesn't find
> anything in order to fix only errors ?!

I suggest filing a bug in the tracker.

Thanks,

Stephen.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
In reply to this post by Kristof Beyls via cfe-dev
Hi Alexander,

clang-tidy runs the frontend first, so if the frontend detects errors it
will report them as well.

There is a feature in the frontend itself that tries to fix bugs, e.g.
s"foo.method()"/"foo->method()" fixits can be emitted.

I think that is closer to what you want and might be a better place to
request that feature.

Best Regards
Jonas

Am 22.10.19 um 00:59 schrieb Alexander Lanin via cfe-dev:

> Hello,
>
> clang-tidy can not only be used to improve code, but also to make it work in
> the first place.
>
> Taking an example from
> https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dependent
> -template-recover.cpp
>
>     template<typename T, typename U, int N>
>     struct X {
>       void f(T* t) {
>         t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
> as a dependent template name}}
>       }
>     };
>
> Clang-tidy is capable of fixing that error.
> However it's not possible to fix it without running any other checks?!
> e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors
> but it performs all sorts of other changes.
>
> The best approach seems to be to pick some checker that doesn't find
> anything in order to fix only errors ?!
>
> Thanks,
> Alexander Lanin
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
Done, thanks.
https://bugs.llvm.org/show_bug.cgi?id=43816


-----Ursprüngliche Nachricht-----
Von: Jonas Toth <[hidden email]>
Gesendet: Donnerstag, 24. Oktober 2019 20:13
An: Alexander Lanin <[hidden email]>; [hidden email]
Betreff: Re: [cfe-dev] Using clang-tidy to fix compiler errors

Hi Alexander,

clang-tidy runs the frontend first, so if the frontend detects errors it will report them as well.

There is a feature in the frontend itself that tries to fix bugs, e.g.
s"foo.method()"/"foo->method()" fixits can be emitted.

I think that is closer to what you want and might be a better place to request that feature.

Best Regards
Jonas

Am 22.10.19 um 00:59 schrieb Alexander Lanin via cfe-dev:

> Hello,
>
> clang-tidy can not only be used to improve code, but also to make it
> work in the first place.
>
> Taking an example from
> https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dep
> endent
> -template-recover.cpp
>
>     template<typename T, typename U, int N>
>     struct X {
>       void f(T* t) {
>         t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
> as a dependent template name}}
>       }
>     };
>
> Clang-tidy is capable of fixing that error.
> However it's not possible to fix it without running any other checks?!
> e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors but
> it performs all sorts of other changes.
>
> The best approach seems to be to pick some checker that doesn't find
> anything in order to fix only errors ?!
>
> Thanks,
> Alexander Lanin
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
Hi,

I think the usual way to do this is to disable checks and then select the ones you need. It's not a bug, it's a feature.

Matthieu

Le sam. 26 oct. 2019 à 11:55, Alexander Lanin via cfe-dev <[hidden email]> a écrit :
Done, thanks.
https://bugs.llvm.org/show_bug.cgi?id=43816


-----Ursprüngliche Nachricht-----
Von: Jonas Toth <[hidden email]>
Gesendet: Donnerstag, 24. Oktober 2019 20:13
An: Alexander Lanin <[hidden email]>; [hidden email]
Betreff: Re: [cfe-dev] Using clang-tidy to fix compiler errors

Hi Alexander,

clang-tidy runs the frontend first, so if the frontend detects errors it will report them as well.

There is a feature in the frontend itself that tries to fix bugs, e.g.
s"foo.method()"/"foo->method()" fixits can be emitted.

I think that is closer to what you want and might be a better place to request that feature.

Best Regards
Jonas

Am 22.10.19 um 00:59 schrieb Alexander Lanin via cfe-dev:
> Hello,
>
> clang-tidy can not only be used to improve code, but also to make it
> work in the first place.
>
> Taking an example from
> https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dep
> endent
> -template-recover.cpp
>
>     template<typename T, typename U, int N>
>     struct X {
>       void f(T* t) {
>         t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
> as a dependent template name}}
>       }
>     };
>
> Clang-tidy is capable of fixing that error.
> However it's not possible to fix it without running any other checks?!
> e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors but
> it performs all sorts of other changes.
>
> The best approach seems to be to pick some checker that doesn't find
> anything in order to fix only errors ?!
>
> Thanks,
> Alexander Lanin
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
Quantitative researcher, Ph.D.
Blog: http://blog.audio-tk.com/
LinkedIn: http://www.linkedin.com/in/matthieubrucher

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using clang-tidy to fix compiler errors

Kristof Beyls via cfe-dev
I think there's some confusion here.

I think Alex doesn't want to run any checks - just wants the clang diagnostic fixits applied - they can get this behavior by running clang-tidy with some checks enabled, but there's no "run clang-tidy with no checks, just with clangs actual errors/fixits".

I think maybe Alex should be running clang -fixit ? That might be how you get "clang-tidy without any tidy checks" behavior.

On Sat, Oct 26, 2019 at 4:00 AM Matthieu Brucher via cfe-dev <[hidden email]> wrote:
Hi,

I think the usual way to do this is to disable checks and then select the ones you need. It's not a bug, it's a feature.

Matthieu

Le sam. 26 oct. 2019 à 11:55, Alexander Lanin via cfe-dev <[hidden email]> a écrit :
Done, thanks.
https://bugs.llvm.org/show_bug.cgi?id=43816


-----Ursprüngliche Nachricht-----
Von: Jonas Toth <[hidden email]>
Gesendet: Donnerstag, 24. Oktober 2019 20:13
An: Alexander Lanin <[hidden email]>; [hidden email]
Betreff: Re: [cfe-dev] Using clang-tidy to fix compiler errors

Hi Alexander,

clang-tidy runs the frontend first, so if the frontend detects errors it will report them as well.

There is a feature in the frontend itself that tries to fix bugs, e.g.
s"foo.method()"/"foo->method()" fixits can be emitted.

I think that is closer to what you want and might be a better place to request that feature.

Best Regards
Jonas

Am 22.10.19 um 00:59 schrieb Alexander Lanin via cfe-dev:
> Hello,
>
> clang-tidy can not only be used to improve code, but also to make it
> work in the first place.
>
> Taking an example from
> https://github.com/llvm-mirror/clang/blob/master/test/SemaTemplate/dep
> endent
> -template-recover.cpp
>
>     template<typename T, typename U, int N>
>     struct X {
>       void f(T* t) {
>         t->f0<U>(); // expected-error{{use 'template' keyword to treat 'f0'
> as a dependent template name}}
>       }
>     };
>
> Clang-tidy is capable of fixing that error.
> However it's not possible to fix it without running any other checks?!
> e.g. this works fine: clang-tidy --checks="*" test.cpp -fix-errors but
> it performs all sorts of other changes.
>
> The best approach seems to be to pick some checker that doesn't find
> anything in order to fix only errors ?!
>
> Thanks,
> Alexander Lanin
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
Quantitative researcher, Ph.D.
Blog: http://blog.audio-tk.com/
LinkedIn: http://www.linkedin.com/in/matthieubrucher
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev