18

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

2
  • 6
    Try -fsyntax-only. Commented Dec 28, 2012 at 16:49
  • @KerrekSB: Move it to answer :) Commented Dec 28, 2012 at 19:25

2 Answers 2

18

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

Sign up to request clarification or add additional context in comments.

1 Comment

However it's important to note that the flag is a lot more useful for clang, for G++ it doesn't do template instantiation, which means lots of possible diagnostics are missed
4

In addition to the other replies, gcc is doing some analysis during compilation (and even during some optimization passes). So you could discard the generated code and still get all the warnings with e.g. gcc -Wall -O -c code.c -o /dev/null

Notice that you could extend GCC with your additional passes doing some additional, application specific, checks and warnings, e.g. with MELT (a high level domain specific language to extend GCC).

If you want strong static analysis and are willing to give additional annotations for that purpose consider also Frama C.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.