tags:

views:

190

answers:

3

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?

A: 

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
A: 

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
+4  A: 

-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
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
@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.
honk