llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

fix-it in clang #43161

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 43816
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

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.

llvmbot 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.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 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.