问题
I just updated my arch linux system to the latest which includes gcc 7.1.1. Trying to build this:
#include <functional>
int main(int argc, char** argv) {
return 1;
}
using the command
clang++ main.cpp -std=c++1z
results in the error:
In file included from main.cpp:1:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/unordered_map:47:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/hashtable.h:37:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/node_handle.h:39:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:27: error: use of class template 'optional'
requires template arguments
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:451:11: note: template is declared here
class optional
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:40: error: expected ';' at end of declaration
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:41: error: cannot use arrow operator on a type
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
Is this an error on my part, arch linux, or clang?
Update: (forgot to add versions)
- gcc package version 7.1.1-2 (provides /usr/include/c++ dir)
- clang package version 4.0.0-3
回答1:
Little late but I would like to sum it up.
This:
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
is the example of deduction guides. Here you can find nice explanation of this language feature.
New version of libstdc++ uses it in its implementation when -std=c++17 or c++1z flag is in use. Unfortunately Clang does not support this feature yet. Clang C++1z status page reports it as available only on SVN.
You can find bug report for Arch Linux here.
来源:https://stackoverflow.com/questions/44262236/clang-4-build-error-on-functional-with-c1z