C++ – How to run GCC/Clang for static analysis? (warnings only)

cclangcompiler-constructiongccstatic analysis

Without compiling code, I would like GCC or Clang to report warnings.
Is it possible to run the compiler for static analysis only?
I can't find a way to pass the compiler warning flags and tell it not to compile.

edit: just found that clang has a static analyser

Best Answer

Both GCC and Clang have an option -fsyntax-only that makes the compiler only perform syntax checking without any actual compilation.