GCC 4.8正在逆转可变参数模板参数包

Azo*_*oth 23 c++ gcc templates variadic c++11

我刚刚升级到GCC 4.8,一些可变参数模板代码不再正确编译.我在下面创建了一个最小的示例:

#include <tuple>
#include <iostream>

template <class T, class ... OtherT>
void something( std::tuple<T, OtherT...> & tup )
{
  std::cout << std::get<1>(tup) << std::endl;
}

int main()
{
  std::tuple<int, char, bool> myTuple(3, 'a', true);

  // Compiles OK in GCC 4.6.3 but NOT 4.8
  something<int, char, bool>( myTuple );

  // Compiles OK in GCC 4.8 but NOT 4.6.3
  something<int, bool, char>( myTuple );

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个输出将是(如果注释掉GCC 4.6.3/4.8的错误版本)'a'.

GCC 4.6.3产生的错误是:

./test.cpp: In function ‘int main()’:
./test.cpp:18:39: error: no matching function for call to ‘something(std::tuple<int, char, bool>&)’
./test.cpp:18:39: note: candidate is:
./test.cpp:5:6: note: template<class T, class ... OtherT> void something(std::tuple<_Head, _Tail ...>&)
Run Code Online (Sandbox Code Playgroud)

GCC 4.8产生的错误是:

./test.cpp: In function ‘int main()’:
./test.cpp:15:39: error: no matching function for call to ‘something(std::tuple<int, char, bool>&)’
   something<int, char, bool>( myTuple );
                                       ^
./test.cpp:15:39: note: candidate is:
./test.cpp:5:6: note: template<class T, class ... OtherT> void something(std::tuple<_El0, _El ...>&)
 void something( std::tuple<T, OtherT...> & tup )
      ^
./test.cpp:5:6: note:   template argument deduction/substitution failed:
./test.cpp:15:39: note:   mismatched types ‘bool’ and ‘char’
   something<int, char, bool>( myTuple );
Run Code Online (Sandbox Code Playgroud)

看起来在GCC 4.8中,可变参数模板类型在扩展时会被反转,但奇怪的是它们并没有像输出所证明的那样"真正地"反转 - 无论顺序如何,它都是'a'.Clang 3.3同意GCC 4.6.3输出.

这是GCC 4.8中的错误还是其他什么?

编辑:在这里向GCC添加了一个错误报告:http://gcc.gnu.org/bugzilla/show_bug.cgi? id = 56774

Dan*_*rey 15

这看起来像是一个bug,GCC 4.8.0和GCC 4.7.2似乎受到了影响.Clang 3.2和GCC 4.6.3同意第一次调用something是正确的,我真的没有看到GCC 4.7.2+如何认为第二次调用是可以接受的.

我会说:报告一个针对GCC的错误.


更新:我在GCC错误报告中添加了一个简约示例,只是为了帮助它们并证明它是一个纯粹的编译器错误并且与之无关std::tuple.这是减少的代码:

template< typename... > struct X {};

template< typename T, typename... Ts >
void f( X< T, Ts... >& ) {}

int main()
{
    X< int, bool, char > t;
    f< int, char, bool >(t);
}
Run Code Online (Sandbox Code Playgroud)

更新2: GCC 4.7.3,GCC 4.8.1和GCC 4.9现已修复 - 对GCC团队的一次非常快速的修复!