Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 863
ryan0270 Avatar asked May 30 '17 12:05

ryan0270


1 Answers

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.

like image 182
Stro Avatar answered Oct 23 '22 23:10

Stro