将光标移到/点击文章中的句子上,可以查看译文。      显示繁体中文内容    显示简体中文内容

c++ - clang 4 build error on <functional> with c++1z
在 <functional> 上使用 c++1z,C++ clang 4生成错误

73 1

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
时间:原作者:

88 5

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.

原作者:
...