问题
Related, but (IMHO) different: Nested template argument deduction for class templates not working
The following C++17 code is rejected from GCC 8, but clang compiles it without any issues. The GCC's error message is included as a comment just before the problematic line.
Which compiler is correct here?
https://godbolt.org/z/WG6f7G
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});// ({})
}
回答1:
Comments to this question state that this is a GCC bug. It has been filed as GCC bug report 89062.
来源:https://stackoverflow.com/questions/54369677/nested-class-template-argument-deduction-with-parentheses-gcc-vs-clang