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

StackOverflow https://stackoverflow.com/questions/7462820

  •  22-01-2021
  •  | 
  •  

Frage

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++?

War es hilfreich?

Lösung

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.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top