Category : aggregate-initialization

C++20 introduced support for designated initializers. In g++ with -std=c++17, one can use designated initializers and as long as you don’t leave any out, it will compile without any errors or warnings: struct Foo { int a; float b; }; Foo f { .a = 7, .b = 42.1f, }; Yet if I enable -Wpedantic ..

Read more

Aggregate initialization is a special form of list initialization which can be used for aggregate types. An aggregate is an array or a class ([class]) with (1.1) no user-declared or inherited constructors ([class.ctor]), (1.2) no private or protected direct non-static data members ([class.access]), (1.3) no virtual functions ([class.virtual]), and (1.4) no virtual, private, or protected ..

Read more

As far as I understand, the following program should work in C++20 mode: #include <vector> struct B{ int a0, a1; }; int main() { std::vector<B> bs; bs.emplace_back( 0, 0 ); } And it really does in Visual Studio 2019 and gcc 11. But not in clang 12, which produces the error: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/alloc_traits.h:514:4: error: no matching ..

Read more