C++11 使用带有单个参数的元组时出现异常编译错误

C++11 使用带有单个参数的元组时出现异常编译错误,c++11,clang++,C++11,Clang++,我不明白为什么clang不会编译下面的代码,但gcc会编译。没有参数或多个参数到元组有效,单个参数无效 #include <tuple> int main(int , char *[]) { // fails std::tuple<int> a; // works std::tuple<> b; std::tuple<int,int> c; r

我不明白为什么clang不会编译下面的代码,但gcc会编译。没有参数或多个参数到元组有效,单个参数无效

   #include <tuple>

   int main(int , char *[])
   {
       // fails
       std::tuple<int> a;

       // works
       std::tuple<> b;
       std::tuple<int,int> c;
       return 0;
   } 
#包括
int main(int,char*[])
{
//失败
std::元组a;
//工作
std::元组b;
std::元组c;
返回0;
} 
叮当声错误

$ clang++ -std=c++14 tuple.cpp 
In file included from tuple.cpp:1:
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:483:62: error: pack
      expansion contains parameter packs '_Elements' and '_UElements' that have different lengths
      (1 vs. 0)
      return __and_<is_constructible<_Elements, _UElements&&>...>::value;
                                     ~~~~~~~~~  ~~~~~~~~~~   ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:631:21: note: in
      instantiation of function template specialization 'std::_TC<true,
      int>::_MoveConstructibleTuple<>' requested here
                    _MoveConstructibleTuple<_UElements...>()
                    ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:636:19: note: while
      substituting prior template arguments into non-type template parameter [with _UElements = <>]
        constexpr tuple(_UElements&&... __elements)
                  ^~~~~
tuple.cpp:5:21: note: while substituting deduced template arguments into function template 'tuple'
      [with _UElements = <>, $1 = (no value)]
    std::tuple<int> a;
                    ^
In file included from tuple.cpp:1:
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:489:60: error: pack
      expansion contains parameter packs '_UElements' and '_Elements' that have different lengths
      (0 vs. 1)
      return __and_<is_convertible<_UElements&&, _Elements>...>::value;
                                   ~~~~~~~~~~    ~~~~~~~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:633:21: note: in
      instantiation of function template specialization 'std::_TC<true,
      int>::_ImplicitlyMoveConvertibleTuple<>' requested here
                    _ImplicitlyMoveConvertibleTuple<_UElements...>()
                    ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../include/c++/6.1.1/tuple:636:19: note: while
      substituting prior template arguments into non-type template parameter [with _UElements = <>]
        constexpr tuple(_UElements&&... __elements)
                  ^~~~~
tuple.cpp:5:21: note: while substituting deduced template arguments into function template 'tuple'
      [with _UElements = <>, $1 = (no value)]
    std::tuple<int> a;
                    ^
2 errors generated.
$clang++-std=c++14 tuple.cpp
在tuple.cpp中包含的文件中:1:
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../../include/c++/6.1.1/tuple:483:62:错误:pack
展开包含长度不同的参数包“_元素”和“_元素”
(1对0)
返回uu和u::value;
~~~~~~~~~  ~~~~~~~~~~   ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../../include/c++/6.1.1/tuple:631:21:注意:在
此处请求的函数模板专门化“std::\u TC::\u MoveConstructibleTuple”的实例化
_MoveConstructibleTuple()
^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../../../include/c++/6.1.1/tuple:636:19:注意:当
将先前的模板参数替换为非类型模板参数[使用_UElements=]
constexpr元组(_元素和…_元素)
^~~~~
tuple.cpp:5:21:注意:在将推导的模板参数替换为函数模板“tuple”时
[带_UElements=,$1=(无值)]
std::元组a;
^
在tuple.cpp中包含的文件中:1:
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../include/c++/6.1.1/tuple:489:60:错误:pack
扩展包含具有不同长度的参数包“\u元素”和“\u元素”
(0对1)
返回uu和u::value;
~~~~~~~~~~    ~~~~~~~~~ ^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../../include/c++/6.1.1/tuple:633:21:注意:在
此处请求的函数模板专门化“std::_TC::_ImplicitlyMoveConvertibleTuple”的实例化
_隐式ymoveConVertibleTuple()
^
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/../../../../../../../../../include/c++/6.1.1/tuple:636:19:注意:当
将先前的模板参数替换为非类型模板参数[使用_UElements=]
constexpr元组(_元素和…_元素)
^~~~~
tuple.cpp:5:21:注意:在将推导的模板参数替换为函数模板“tuple”时
[带_UElements=,$1=(无值)]
std::元组a;
^
产生2个错误。

@DarkFalcon似乎就是这样。与旧gcc相同版本的clang可在其他机器上使用。Thanks@Adrian-您使用的是哪个版本的clang++?我的3.5编译没有问题。@max66 clang 3.7.1和gcc 6.1.1-在3.7.1和gcc 5.2.0中运行良好-它似乎是一个clangbug@Adrian-不太明白(我的错:我的英语有很大的问题;对不起)。你是说当安装gcc 6.1.1时,你有clang 3.7.1错误,但当安装gcc 5.2.0时,clang 3.7.1编译时没有错误?我看到您使用的是
clang++-std=c++14
,因此我怀疑clang++和与g++6.1.1一起安装的libstdc++之间存在交互问题。建议:安装libc++(如果未安装),并尝试使用libc++(
clang++-std=c++14-stdlib=libc++tuple.cpp