带有括号的“嵌套”类模板参数推导:GCC与clang

Jul*_*ius 5 c++ templates compiler-errors language-lawyer c++17

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

以下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});// ({})
}
Run Code Online (Sandbox Code Playgroud)

Jul*_*ius 2

对该问题的评论表明这是一个 GCC 错误。它已被归档为 GCC 错误报告89062