September 06, 2015 at 06:22 Tags LLVM & Clang

The Makefile in my LLVM & Clang samples project is using g++ by default as the C++ compiler. Even though the officially recommended compiler to build Clang and LLVM is Clang, g++ has worked well because not everyone has Clang installed on their system.

This is going to change very soon, when LLVM and Clang 3.7 are released (any day now, as the release is in RC2 stage). When you build the samples vs. the binary of release 3.7, you'll likely run into compile errors about -Wcovered-switch-default , and maybe other problems. The reason for this has to do with the following:

When LLVM & Clang binary releases are created, they are built with Clang. Starting with 3.7, LLVM & Clang are built with the -Wcovered-switch-default flag by default. This also means that the llvm-config utility will emit this flag when queried for compile flags. And my samples' Makefile uses llvm-config . GCC doesn't yet support -Wcovered-switch-default.

There are two possible solutions for this issue. The best one is to just use Clang to build these samples (and any other code linking with LLVM or Clang themselves). You don't even have to have Clang installed for this; simply download the latest binary release, and point CXX to bin/clang++ in the untarred directory. Everything should work, since Clang will find GCC's include paths, libstd++ and everything else.

An alternative approach, if you just must stick to GCC for some reason, is to sanitize the flags emitted by llvm-config , removing those that aren't supported before passing them to the compiler. This means you won't be able to use my Makefile as is, though.

In the long run, I suggest to just use Clang to build LLVM & Clang. This is what the LLVM core developers do to test things and build releases, so this is the way least susceptible to unexpected problems.