Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for the Clang Static Analyzer and Clang Tidy
https://codechecker.readthedocs.io
Apache License 2.0
2.15k stars 358 forks source link

Codechecker adding '-Wno-deprecated' causes clang-tidy to fail, when used with precompiled headers #4183

Open invy opened 4 months ago

invy commented 4 months ago

Describe the bug After CodeChecker update I've been getting clang-diagnostic-errors reports by clang-tidy:

1 error generated.
Error while processing /path/to/my/code.cpp.
error: __DEPRECATED predefined macro was enabled in PCH file but is currently disabled [clang-diagnostic-error]
Found compiler error(s).

CodeChecker version CodeChecker Version 6.23.1

To Reproduce Steps to reproduce the behaviour:

To reproduce the behavior create add precompiled header into your cmake project:

  1. Create CMake Projejct...

    add_executable(mytarget main.cpp)
    target_precompile_headers(mytarget PRIVATE some_header_file.h)
    add_compile_options(-Wdeprecated)
  2. Scan/Analyze with clang-tidy enabled. (Standard options)

  3. See error

Description I've looked into the warning flags, CodeChecker passes to the clang-tidy and found one in particular "-Wno-deprecated" The flag has a side-effect, it removes a preprocessor definition, __DEPRECATED, which was added in my CMake Project.

https://clang.llvm.org/docs/ClangCommandLineReference.html

-Wdeprecated, -Wno-deprecated[¶](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-Wdeprecated)

Enable warnings for deprecated constructs and define __DEPRECATED
whisperity commented 4 months ago

Just for confirmation, could you please run an analysis but pass --enable clang-diagnostic-deprecated to CodeChecker analyze? It should turn that diagnostic flag back on, and thus side-step the problem. The issue is that warning flags need to be transformed, otherwise Tidy will emit Sema-level diagnostics as-if (in format) they were Tidy checkers...

(The fact that warning flags potentially change the behaviour of the code is a whole other can of worms...)