Search code examples
clangstatic-analysisclang-static-analyzerclang-tidy

clang-tidy: Analyze file with multiple errors


Is it possible to analyze a C/C++ file in clang-tidy, while ignoring its syntax/compilation errors?

I have a very big file that has several compilation errors, but I still want to analyze it with clang-tidy.

I'm getting the following error message:

20 warnings and 20 errors generated.
Error while processing <myfile.c>
error: too many errors emitted, stopping now [clang-diagnostic-error]

I saw that in a smaller file, it is possible to have some syntax errors, but still, issues like index past the end of the array are displayed.

Is there a way to still have my file to be analyzed, despite the errors (like increasing the number of possible errors)?


Solution

  • You may instruct clang-tidy to continue processing errors by applying -ferror-limit=0 to the compilation flags, that is, add the following to clang-tidy command line:

    -extra-arg=-ferror-limit=0

    The default value for -ferror-limit is indeed 20.

    Alternatively, you may want to set the limit to a higher number of your choice, rather than disabling the limitation completely.

    Note that if you are using the run-clang-tidy.py script, rather than clang-tidy directly, you'll need version 5.0 for -extra-arg parameter support.