"Nested" 带括号的类模板参数推导:GCC vs. clang

"Nested" class-template argument deduction with parentheses: GCC vs. clang

本文关键字:GCC clang vs 参数 Nested      更新时间:2023-10-16

相关,但(恕我直言)不同:类模板的嵌套模板参数推导不起作用

以下 C++17 代码被 GCC 8 拒绝,但 clang 编译它没有任何问题。GCC 的错误消息作为注释包含在有问题的行之前。

哪个编译器在这里是正确的?

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});// ({})
}

对此问题的评论指出这是一个 GCC 错误。它已被归档为 GCC 错误报告 89062。