我正在尝试通过 Clang 的静态代码分析器工具静态分析我的代码scan-build
,当我使用命令运行代码时scan-build g++
,它会为我提供错误报告,但是当我尝试使用 CMake 和scan-build make
命令做同样的事情时,它会告诉我没有发现任何错误。
我已经尝试通过 bash 导出命令替换CC
和变量,使用和标志并使用. 所有这一切都没有让我找到正确的解决方案,恐怕这不能与 CMake/make 一起使用。CXX
--use_cc
--use_c++
scan-build make TARGET
scan-build
- Clang 版本 8.0.0 (tags/RELEASE_800/final)
- Gcc 版本 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04)
这是一个简单的例子。
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER "usr/bin/clang")
set(CMAKE_CXX_COMPILER "usr/bin/clang++")
set(CMAKE_AR "usr/bin/llvm-ar")
set(CMAKE_LINKER "usr/bin/llvm-ld")
set(CMAKE_NM "usr/bin/llvm-nm")
set(CMAKE_OBJDUMP "usr/bin/llvm-objdump")
set(CMAKE_RANLIB "usr/bin/llvm-ranlib")
project(scan-build-test)
add_executable(${PROJECT_NAME} main.cpp)
主文件
#include <iostream>
int main()
{
int *a;
std::cout << a << std::endl;
}
当前行为 g++:
scan-build g++ main.cpp -o main
scan-build: Using 'usr/bin/clang-8' for static analysis main.cpp:6:2: warning: 1st function call argument is an uninitialized value
std::cout << a << std::endl;
^~~~~~~~~~~~~~
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2019-05-30-134021-30676-1' to examine bug reports.`
当前行为 CMake & make:
cmake .
scan-build make
scan-build: Using 'usr/bin/clang-8' for static analysis
[ 50%] Building CXX object CMakeFiles/scan-build-test.dir/main.cpp.o
[100%] Linking CXX executable scan-build-test
[100%] Built target scan-build-test
scan-build: Removing directory '/tmp/scan-build-2019-05-30-134302-30720-1' because it contains no reports.
scan-build: No bugs found.