匿名临时和类模板参数扣除-GCC与Clang
Anonymous temporaries and class template argument deduction - gcc vs clang
考虑以下代码段:
template <typename T>
struct foo
{
foo(T) { }
};
int main()
{
foo{0};
}
g 7 愉快地创建了类型foo
的临时对象,推论T = int
。
clang 5和6 拒绝编译代码:
error: expected unqualified-id foo{0}; ^
wandbox上的实时示例
这是一个clang虫的错误,还是标准中的某些东西可以防止 class template参数扣除启动未命名的临时性?
clang bug(#34091)
来自[dcl.type.class.deduct]:
推导类型类型的占位符也可以在[...] 或作为显式类型转换(功能符号)中的[...] 或作为 simple-type-specifier 。推论类型类型的占位符不得出现在任何其他情况下。 [示例:
template<class T> struct container { container(T t) {} template<class Iter> container(Iter beg, Iter end); }; template<class Iter> container(Iter b, Iter e) -> container<typename std::iterator_traits<Iter>::value_type>; std::vector<double> v = { /* ... */ }; container c(7); // OK, deduces int for T auto d = container(v.begin(), v.end()); // OK, deduces double for T container e{5, 6}; // error, int is not an iterator
- 结束示例]
相关文章:
- 类模板参数推导-clang和gcc不同
- 带有自动参数的函数使用 GCC 编译,但不使用 Visual C++ 编译
- GCC/CLang不同意模板模板参数的部分特化
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 使用具有默认参数的函数模板进行 decltype 会使结果混乱(一个有趣的问题或 gcc 的错误)
- constexpr 函数的常量引用参数:gcc/msvc vs clang/icc
- 隐蔽的 gcc 参数到 CMake 文件
- typedef名称与可变模板参数名称一致时出现GCC错误
- 将带有模板化方法的类作为带有GCC的模板参数传递
- 在if constexpr中使用带参数包的概念时,升级到gcc 9后出现编译错误
- 模板模板参数导致Clang下的编译器错误,而不是GCC
- GCC 仪器 - 是否可以自动输出函数的参数?
- 带有 gcc 和 clang 的可变参数宏扩展的奇怪行为
- 修改嵌套 lambda 中捕获的参数:gcc 与 clang?
- 使用函数参数作为常量表达式的一部分 - gcc vs clang
- 使用 GCC 5 进行模板参数阴影
- 类数据成员指针的非类型模板参数包无法使用 gcc 编译
- 在 mingw64-gcc 上可能存在可变参数的错误
- 在折叠表达式中扩展参数包作为 lambda 捕获的一部分 - gcc 与 clang
- 打开模板参数:GCC 是否删除开关