19

Is there some ultra fast "syntax check my code, but don't compile mode" for g++/clang? Where the only goal is to just check if the code I have is valid C++ code?

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
anon
  • 41,035
  • 53
  • 197
  • 293

3 Answers3

18

-fsyntax-only for GCC, this should probably work for Clang as well since they emulate GCC's command line options. Whether or not it's significantly faster, you'll have to time.

Dan Olson
  • 22,849
  • 4
  • 42
  • 56
  • The speed issue is really how much time is spent on read source I/O, on syntax checking, how much time compiling, and how much time doing object output I/O. I suspect that with enough source includes read I/O may be a large portion and you'll see minimal gain from syntax checking only. – Mark B Apr 05 '10 at 14:33
  • 1
    @Mark: In my experience caching the compiled output with ccache made almost always sense. And don't forget that C++ might also include templates which can make pure compile times skyrocket. – Benjamin Bannier Jun 19 '10 at 22:31
  • Note that in g++, this only parses the code and doesn't instantiate, so you can miss many errors. clang++ stops after instantiation, which can take a bit longer but is more useful. Also, some of the g++ warnings are produced during the code optimization phase, so you'll miss those as well. – Marc Glisse Jan 10 '13 at 17:35
0

You can have a look at gcc-xml ( http://www.gccxml.org/HTML/Index.html ), which reuses the gcc frontend to produce an xml description of the source.

Another option is to use the edg frontend ( http://www.edg.com/index.php?location=c_frontend ), but is is not open source, and far from cheap.

tonio
  • 10,355
  • 2
  • 46
  • 60
0

Maybe cppcheck is an option for you? I do not know exactly what result you want. cppcheck is not a pure syntax check. And if cppcheck is fast enougth.

jpyllman
  • 307
  • 2
  • 6