Jul*_*ius 5 c++ templates compiler-errors language-lawyer c++17
相关,但(IMHO)不同:类模板的嵌套模板参数推导不起作用
以下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});// ({})
}
Run Code Online (Sandbox Code Playgroud)