clang-tidy -fix does not apply any changes

Viewed 3404

I'm running clang-tidy with the following command:

run-clang-tidy.py -checks="-*,cppcoreguidelines-*,hicpps-*" -header-filter=".*" -fix"

(or clang-tidy -checks="-*,cppcoreguidelines-*,hicpps-*" -header-filter=".*" -fix" also works)

This returns a lot of errors. It also says applying fixes... in the terminal since I added the -fix option.

My problem is that for the cppcoreguidelines-* and hicpps-* fixes are not applied, only shown. Does the checks that I have choose not to support fixing my 1000 problems?

2 Answers

You should use the -fix-errors option instead of just -fix. The latter will not apply any fixes if compiler errors are present. See the clang-tidy documentation:

  -fix                          -
                                  Apply suggested fixes. Without -fix-errors
                                  clang-tidy will bail out if any compilation
                                  errors were found.
  -fix-errors                   -
                                  Apply suggested fixes even if compilation
                                  errors were found. If compiler errors have
                                  attached fix-its, clang-tidy will apply them as
                                  well.

I also ran into the same issue while I was trying to automatically apply clang-tidy fixes via LLVM's run-clang-tidy python script:

The Root of the problem for me was a mismatch of the run-clang-tidy.py script, clang-tidy and the version of clang-apply-replacements. The latter was version 10 instead of 11, so installing clang-tidy-11 and linking clang-apply-replacements to the clang-apply-replacements-11 fixed the issue for me. I also downloaded the run-clang-tidy script from LLVM's repository with the matching tag.

Is this also the cause of your problem? If the reported versions don't match, similar steps might also solve your problem.

clang++ --version
clang-tidy --version
clang-apply-replacements --version
Related