“嵌套"带括号的类模板参数推导:GCC与clang [英] "Nested" class-template argument deduction with parentheses: GCC vs. clang
本文介绍了“嵌套"带括号的类模板参数推导:GCC与clang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
相关但(IMHO)不同:嵌套模板参数推论类模板不起作用
Related, but (IMHO) different: Nested template argument deduction for class templates not working
以下C ++ 17代码被GCC 8拒绝,但是clang对其进行编译没有任何问题.在出现问题的行之前,GCC的错误消息作为注释包含在内.
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?
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 .
Comments to this question state that this is a GCC bug. It has been filed as GCC bug report 89062.
这篇关于“嵌套"带括号的类模板参数推导:GCC与clang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文