c++clangscan-build

Clang scan-build identifying CXX compiler as GNU 9.1.0, not clang


I was trying to use scan-build with cmake. Following scan-build make after scan-build cmake. But when using scan-build, it is identifying CXX compiler as GNU 9.1.0. But if we don't use scan-build it properly identify CXX as clang. Because of CXX compiler identified as GNU 9.1.0, checks for some diagnostic flags in clang (eg, Wunreachable_code_break, Werror_range_loop_analysis) are getting failed.

Output, while using scan-build:

scan-build: Using '../clang/9.0.0/bin/clang-9' for static analysis
-- The CXX compiler identification is GNU 9.1.0
-- Check for working CXX compiler: ../clang/9.0.0/libexec/c++-analyzer
-- Check for working CXX compiler: ../clang/9.0.0/libexec/c++-analyzer -- works

Output, without scan-build:

-- The CXX compiler identification is Clang 9.0.0
-- Check for working CXX compiler: ../clang/9.0.0/bin/clang++
-- Check for working CXX compiler: ../clang/9.0.0/bin/clang++ -- works

How to make sure scan-build have to identify clang as CXX compiler?


Solution

  • Reading the Manual

    The script uses simple heuristics to determine which compiler should be used (it defaults to clang on Darwin and gcc on other platforms).

    ...

    scan-build provides the --use-cc and --use-c++ options to hardwire which compiler scan-build should use for building your code.

    You'll want to change the CMake configuration so that the call to scan-build looks like...

    scan-build --use-c++ ${CMAKE_CXX_COMPILER} ...