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

佐手、 提交于 2021-02-05 04:59:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!