This code compiles without warning in GCC 11 and Clang 13 (in C++20 mode)
struct A {
int x, y;
};
struct B : A { };
int main () {
A a{1,2};
B b{3,4}; // Clang 12 wants B b{{3,4}}
return a.x * b.x + a.y * b.y;
}
but in Clang 12 We get
<source>:10:9: warning: suggest braces around initialization of subobject [-Wmissing-braces]
B b{3,4};
https://godbolt.org/z/Kdnon9575
Might be related to:
Why does Clang 12 refuse to initialize aggregates in the C++20 way?
and these papers
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1975r0.html
Are single braces officially supported (without warnings) under C++20 for initialising these simple POD Derived classes? If so, where does the standard say that, so we can rely on it?
In C++17 the double braces are required, to avoid warnings, yes?
And in C++14 single braces are a hard error because a derived struct is not an aggregate, yes?