can "clang --analyze" return non-zero result?

Hi Everyone,

When I run static analyzer from clang with clang++ --analyze, is there a way to make clang return a non-zero status code in case any warning from the analyzer is reported? (I am looking for something analogous to -Werror for normal compiler warnings.)



Hi Andrzej,

Clang itself might not have this flag, but scan-build has the --status-bugs. Alternatively you can ask Clang to output the report in .plist file, and then you can parse that file. (So you end up writing a wrapper around Clang, but that’s nearly the same thing what scan-build is doing.)


Thanks for the advice. So, I tried using scan-build instead, but I run onto a problem. I am compiling with clang with a gcc toolset:

clang++ -std=c++11 -stdlib=libstdc++ --gcc-toolchain=my/path/gcc-5.4.0 -Wall -Wextra main.cpp

And it works fine. But when I add scan-build atop:

scan-build --force-analyze-debug-code --status-bugs -v -v -v clang++ -std=c++11 -stdlib=libstdc++ --gcc-toolchain=/my/path/gcc-5.4.0 -Wall -Wextra main.cpp

Somehow it accesses standard library header files from a different, older g++ version, under path /usr/lib/gcc/x86_64-redhat-linux/4.4.7/ which I never wanted to use. Is there some way to instruct scan-build which path it should use for libstdc++ header files?