Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

fix-it in clang #42786

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR43816
Status NEW
Importance P enhancement
Reported by Alexander Lanin (llvm@alex.lanin.de)
Reported on 2019-10-26 03:57:21 -0700
Last modified on 2019-11-05 10:06:50 -0800
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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 ?!

Clang itself emits the same warning and suggestion, but there is no way to fix-
it from there. See https://godbolt.org/z/iXXy4o

According to http://lists.llvm.org/pipermail/cfe-dev/2019-October/063703.html
I'm hereby trying to file the idea here to have either some clang -fix option
or clang-tidy running without mandatory checkers.
Quuxplusone commented 5 years ago

Clang itself emits the same warning and suggestion, but there is no way to fix-it from there.

This can be accomplished today by using the -fixit flag. Right now that's not exposed by the driver, so you need to use -Xclang -fixit; maybe we should consider exposing it for end user use.

Quuxplusone commented 5 years ago
One more thing: it's impossible to disable those fix-its in clang-tidy. They
are always enabled.

Use-Case: I'm creating separate commits for each clang-tidy fixit while ~100
other people write more code. So the result is that sometimes a clang fix-it
sneaks into one of my commits.
E.g. I want a commit with only modernize-use-equals-default, but I have
(correct) improvements about "return std::move(...)" --> "return ..." in the
same commit. I have to remove them manually in order to apply them separately
later.