相关但(恕我直言)不同:Nested template argument deduction for class templates not working
以下 C++17 代码被 GCC 8 拒绝,但 clang 编译它没有任何问题。 GCC 的错误消息作为注释包含在有问题的行之前。
这里哪个编译器是正确的?
template<class T>
struct Foo {
Foo(T) {}
};
template<class T>
struct Bar {
Bar(T) {};
};
void works() {
Bar bar{1};// {}
Foo foo(bar);// ()
}
void works_too() {
Foo foo{Bar{1}};// {{}}
}
void error_in_gcc() {
// error: 'auto' parameter not permitted in this context
Foo foo(Bar{1});// ({})
}
void but_this_works() {
Foo(Bar{1});// ({})
}
最佳答案
对该问题的评论表明这是一个 GCC 错误。它已被归档为 GCC 错误报告 89062 .
关于c++ - "Nested"带括号的类模板参数推导 : GCC vs. clang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54369677/