Why does Clang 12 refuse to initialize aggregates in the C++20 way?

This is a C++20 feature that allows aggregate initialization through the standard constructor syntax, rather than the typical braced-list initialization syntax. (Note that this only works if the parameters cannot be used in a valid call to a default or copy/move constructor. If they could, that would be called instead of performing aggregate initialization.) According … Read more

Narrowing conversions in C++0x. Is it just me, or does this sound like a breaking change?

I ran into this breaking change when I used GCC. The compiler printed an error for code like this: void foo(const unsigned long long &i) { unsigned int a[2] = {i & 0xFFFFFFFF, i >> 32}; } In function void foo(const long long unsigned int&): error: narrowing conversion of (((long long unsigned int)i) & 4294967295ull) … Read more

When is a private constructor not a private constructor?

The trick is in C++14 8.4.2/5 [dcl.fct.def.default]: … A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration. … Which means that C‘s default constructor is actually not user-provided, because it was explicitly defaulted on its first declaration. As such, C has no user-provided constructors and is … Read more

C++11 aggregate initialization for classes with non-static member initializers

In C++11 having in-class member initializers makes the struct/class not an aggregate — this was changed in C++14, however. This is something I found surprising when I first ran into it, the rationale for this restriction is that in-class initializers are pretty similar to a user defined constructor but the counter argument is that no … Read more