类类型非类型模板参数初始化不编译 [英] Class type non-type template parameter initialization does not compile
本文介绍了类类型非类型模板参数初始化不编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的印象是,以下内容应成为新的C ++ 20标准下的有效代码:
I was under the impression that the following should become valid code under the new C++20 standard:
struct Foo
{
int a, b;
};
template<Foo>
struct Bar
{};
Bar<{.a=1, .b=2}> bar;
但是,设置了 -std = c ++ 20
的 gcc 10.2.0
抱怨:无法将'{1,2}'从'将<大括号括起来的初始化程序列表>'设置为'Foo'
,Clang也无法编译此代码段.有人可以指出为什么它的格式不正确吗?
Yet, gcc 10.2.0
, with -std=c++20
set complains: could not convert ‘{1, 2}’ from ‘<brace-enclosed initializer list>’ to ‘Foo’
and Clang cannot compile this snippet either. Can someone point out why it is not well formed?
推荐答案
此模板参数
{.a=1, .b=2}
查看全文