According to clang's C++-1z status page, I believe 4.0 should support C++17 std::optional
.
However I'm having trouble getting it to work. See this simple example:
#include <optional>
int main() {
return 0;
}
Trying to compile it in various ways, all fail:
$ clang++-4.0 main.cpp
In file included from main.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/optional:33:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/bits/c++17_warning.h:32:2: error: This file
requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the
-std=c++17 or -std=gnu++17 compiler options.
#error This file requires compiler and library support \
^
1 error generated.
(this alone is a bit weird as the error mentions adding -std=c++17 but it turns out the flag's name is c++1z and there is no c++17:)
$ clang++-4.0 -std=c++17 main.cpp
error: invalid value 'c++17' in '-std=c++17'
Anyway let's proceed:
$ clang++-4.0 -std=c++1z main.cpp
In file included from main.cpp:1:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/optional:1032:27: error: use of class template
'optional' requires template arguments
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/optional:451:11: note: template is declared
here
class optional
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/optional:1032:40: error: expected ';' at end of
declaration
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/optional:1032:41: error: cannot use arrow
operator on a type
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
3 errors generated.
Last try:
$ clang++-4.0 -std=c++1z -stdlib=libc++ main.cpp
main.cpp:1:10: fatal error: 'optional' file not found
#include <optional>
^~~~~~~~~~
1 error generated.
clang info:
$ clang++-4.0 --version
clang version 4.0.1-svn305187-1~exp1 (branches/release_40)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Am I doing something wrong?