I want to understand which version of clang Apple installed in my macbook, to see with c++11 and/or c++14 features are available. I typed this command:
clang
The (Apple) version number of the compiler is mostly useless, since you also need to consider whether your code is compiled with libstdc++
or with libc++
(or any other standard library) - and which version of those.
If you want to test for language or library features, it is better to check other defined values, e.g., __cplusplus
, __cpp_constexpr
, __cpp_variadic_templates
, etc. It is not perfect, but it seems to work better (if you want portability) in my experience and the support from all major compiler is improving.
Each C++ standard version defines a value for __cplusplus
, some compilers use intermediate values to say "we already started on C++14, but we are not there yet". Use >=
to test when needed.
The other feature test macros are similar, you can find the current version at N4440. Not all compilers implement N4440, though.
Take a look at https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
------------------------------------------------------------------------------------
Xcode cctools[93] ld64[94] LLVM[85] Clang version string[95]
8.3.3 898 278.4 3.9.0svn[85] 8.1.0 (clang-802.0.42)[80]
9.0 900 302.3 4.0.0?[86] 9.0.0 (clang-900.0.37)[80]
9.1 900 302.3.1 4.0.0?[87] 9.0.0 (clang-900.0.38)[80]
9.2 900 305 4.0.0?[88] 9.0.0 (clang-900.0.39.2)[80]
9.3 906 351.8 5.0.2?[89] 9.1.0 (clang-902.0.39.1)[80]
9.3.1 906 351.8 5.0.2?[89] 9.1.0 (clang-902.0.39.1)[80]
9.4 906 351.8 5.0.2?[90] 9.1.0 (clang-902.0.39.2)[80]
9.4.1 906 351.8 5.0.2?[90] 9.1.0 (clang-902.0.39.2)[80]
10.0 921.0.1 409.12 6.0.1?[91] 10.0.0 (clang-1000.11.45.2)[80]
10.1 921.0.1 409.12 6.0.1?[92] 10.0.0 (clang-1000.11.45.5)[80]
For example, Apple CLang 10.x is LLVM 6.0.1 based.
One can try to compile some file with --verbose option.
For example: c++ --verbose -c test1.cpp
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test1.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -coverage-file /Users/az/ctest/test1.cpp -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.0.2 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/az/ctest -ferror-limit 19 -fmessage-length 130 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test1.o -x c++ test1.cpp
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin14.5.0
It does print LLVM svn version (3.7.0 in our example)