Compile with c++17 mac

Xcode brings its own complete toolchain, including headers and the actual compiler.

Apple LLVM version 9.0.0 (clang-900.0.39.2) (which ships with Xcode 9.2) does not support the usage of the flag -std=c++17 since its too old. The optional header is only included under the folder experimental/. Which is why you need to #include <experimental/optional>

In order to compile your program with c++17 support using the compiler which comes with Xcode 9.2 you need to use the -std=c++1z flag.

Xcode 9.3 will be shipped with Apple LLVM version 9.1.0 (clang-902.0.30) which has support for the -std=c++17 flag. However the optional header is as of today still under the experimental/ subdirectory. This might change during the betas.


Here is what I get with this tests:

#include <experimental/optional>


int main(int, char* []) {
    return 0;
}

g++ -std=c++17 -o test test.cpp
error: invalid value 'c++17' in '-std=c++17'
g++ -std=c++1z -o test test.cpp

Did you try the c++1z argument? Also of note my test compiles without the -std=c++1z argument provided.

I think I'm on a newer version of OSX than you:

Target: x86_64-apple-darwin17.4.0