Struct non-type template parameter + agregate initialization: standard in c++20 or not

Viewed 100

The following snippet extracted from this post compiles with some recent gcc and msvc, but not with the latest clang.

Will it end compiling with clang, or is it some non-standard stuff that some compilers accept and other don't?

Thanks!

struct Foo
{
  int a, b;
};

template<Foo>
struct Bar
{};

Bar<{.a=1, .b=2}> bar;

At this time with clang one has to do this to get it compiled:

Bar<Foo{.a=1, .b=2}> bar;
1 Answers

This is 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.

This should work Bar<{.a=1, .b=2}> but is currently rejected by the grammar, which has not yet been updated to actually make this work.

Related