Hi Milan, On Sat, Sep 1, 2018 at 1:11 AM, Milan Andric via cfe-users wrote: (snip) > > Test program: > > ```test.cpp > #include <optional> > int main() > { > std::optional<int> o1; > } > ``` > > Error I am having below. I tried with a few different flags but always with > the same failure. > > ``` > $ clang++-6.0 -std=c++17 -o test.o test.cpp > test.cpp:1:10: fatal error: 'optional' file not found > #include <optional> > ^~~~~~~~~~ > 1 error generated. > ``` > > Clang version and linkage info. > > ``` > $ clang++-6.0 --version > clang version 6.0.1-svn334776-1~exp1~20180826122732.96 (branches/release_60) > Target: x86_64-pc-linux-gnu > Thread model: posix > InstalledDir: /usr/bin >
In order to use std::optional, you need a Standard C++ Library that supports C++17. For clang, this is libc++, which is usually packaged separately. If clang can't find libc++, it will search for and use GCC's Standard C++ Library (libstdc++). If you run clang++ with the -v switch, you can see what it found. In short, without libc++, clang falls back to GCC's libstdc++. This means that in order to be able to use C++17 *library* features (like std::optional), you need a libstdc++ which implements these features. Bionic Beaver (18.04) includes GCC 7.3, whose libstdc++ implements std::optional. This is why your test succeeds on 18.04 Csaba -- You can get very substantial performance improvements by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler So if you're looking for a completely portable, 100% standards-conformat way to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK) _______________________________________________ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users