Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I use g++ as my compiler, how do I scan a c++ file with the clang static analyzer?

I use g++ to compile my C++ project. When I try to use the clang static analyzer (scan-build) to check my code, I get an error:

>> scan-build g++ main.cpp
could not find clang line

How do I use the scan-build tool with g++?

like image 769
Stuart Berg Avatar asked Nov 04 '22 14:11

Stuart Berg


1 Answers

It appears that scan-build is having trouble recognizing "g++" as the compiler command. It expects "clang" or "gcc". If you replace "g++" with "gcc -lstdc++" to build your project, the scan-build tool will work properly.

>> scan-build gcc -lstdc++ main.cpp
main.cpp:7:3: warning: Assigned value is garbage or undefined
  int y = x;
  ^       ~
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view /var/folders/2l/2l6vhCnVFNad-O8ryd5YO++++TI/-Tmp-/scan-build-2011-09-18-2' to examine bug reports.
like image 71
Stuart Berg Avatar answered Nov 14 '22 21:11

Stuart Berg