clang 4 build error on <functional> with c++1z

匿名 (未验证) 提交于 2019-12-03 02:20:02

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!