c++ - 结构体非类型模板参数+聚合初始化: standard in c++20 or not

标签 c++ templates c++20

以下片段摘自 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/

相关文章:

c++ - SYSTEM 进程是否可以与非 SYSTEM 进程共享数据?

c++ - 几个使用相同原型(prototype)的共享对象导致错误 : file already exists in database

Scala - 使用 Bounds 理解类定义

c++ - C语言的油漆桶

c++ - gflags 不标记任何二进制文件

c++ - 为什么在源文件中特化模板不会导致错误?

c++ - 如果已知,则使用编译时常量

c++ - 比较用 C++20 概念表达的命名要求

c++ - std::strong_ordering 和 std::weak_ordering 的实际意义

c++ - 如何使用概念将参数传递给类方法?