以下片段摘自 this post使用一些最新的 gcc 和 msvc 进行编译,但不使用最新的 clang 进行编译。
它会用 clang 结束编译吗?还是有些编译器接受而其他编译器不接受的一些非标准内容?
谢谢!
struct Foo
{
int a, b;
};
template<Foo>
struct Bar
{};
Bar<{.a=1, .b=2}> bar;
此时,使用 clang 必须执行以下操作才能编译它:
Bar<Foo{.a=1, .b=2}> bar;
最佳答案
这是CWG 2450 :
Since non-type template parameters can now have class types, it would seem to make sense to allow a braced-init-list as a template-argument, but the grammar does not permit it.
这应该可以工作Bar<{.a=1, .b=2}>
但目前已被语法拒绝,语法尚未更新以实际实现此功能。
关于c++ - 结构体非类型模板参数+聚合初始化: standard in c++20 or not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71470692/