Hacker News new | ask | show | jobs
by ynik 2517 days ago
> In C++ there was no way to only run type checking

gcc has -fsyntax-only. Despite the option name, this also includes type checking and template instantiation. AFAIK it reports all compiler errors, though it skips some warnings that are computed by the optimizer (e.g. -Wuninitialized).

1 comments

Is there an easy way to tell CMake or Makefiles to use it ?

I never invoke clang or gcc directly. When using cargo, I use `cargo check` instead of `cargo build`. But in C or C++ depending on the project `make check` might not exist, or it might build all tests and run them, or do something else entirely like checking the formatting using clang-format.

> - CMake > - Easy

Pick one. I'm sure there is though.

It wouldn't be hard with make but then again I'm much more familiar with it than cmake.

So I manage to get it to work in the command line using `CXXFLAGS="$CXXFLAGS -fsyntax-check" cmake ... && make` !
One issue with that is that is, unless there is magic handling of the flag in cmake, it might still attempt (and fail) to run the linking stages. You might need custom targets jut for this.
Dump a compilation database with -CMAKE_EXPORT_COMPILE_COMMANDS=1 and wire up a script to call those commands but with the syntax only flag.