GCC 4.8正在逆转可变模板参数包
GCC 4.8 is reversing variadic template parameter pack
我刚刚升级到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;
}
输出将是(如果注释掉了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 ...>&)
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 );
似乎在GCC 4.8中,可变模板类型在展开时被反转,但奇怪的是,它们并没有"真正"被反转,正如输出所证明的那样-无论顺序如何,它都将是'a'。Clang 3.3与GCC 4.6.3的输出一致。
这是GCC 4.8中的一个bug还是别的什么?
编辑:在这里向GCC添加了一个bug报告:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56774
这看起来像是一个bug, GCC 4.8.0和GCC 4.7.2似乎受到了影响。Clang 3.2和GCC 4.6.3都同意第一次调用something
是正确的,我真的不明白GCC 4.7.2+怎么能认为第二次调用是可以接受的。
我会说:报告一个针对GCC的bug。
更新:我在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);
}
更新2:现在已经修复了GCC 4.7.3, GCC 4.8.1和GCC 4.9 -感谢GCC团队的快速修复!
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用Luacneneneba API正确读取字符串和表参数
- 在派生函数中指定void*参数
- 视图中的参数推导失败:take_while
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- 使用指向成员的指针将成员函数作为参数传递
- 没有名称的C++模板参数
- GCC 4.8正在逆转可变模板参数包