The code below shows a unified class with a non-trivial default constructor (the y member is initialized using the brace-or-equal-initializer element), therefore, if the default constructor for such a class is the default, it must be deleted in accordance with the first paragraph 10.1 / 5. That is, an ad T t; should not compile since there is no default constructor for union T But the code is compiled and executed in clang and GCC.
#include <iostream> union T { int y{1}; float x; char c; T() = default; }; int main() { T t; std::cout << ty << '\n'; }
EDIT
My question above was wrong from the start, since the union of T does not combine the class. I just found out about ยง9.5 / 8 in C ++ 11, which says:
A union class is an association or class that has an anonymous union as a direct member. The combined class X has many options. If X is a union, its variant members are non-static data members; otherwise its members are non-static data elements of all anonymous unions that are members of X.
Now consider the fragment below. It does not compile because the default constructor for the union is removed. But I still do not know which point in paragraph 12.1 / 5 was responsible for this result. Note that, again, union is not a union class, so the first marker point in ยง12.1 / 5 does not apply. But this is what the error message says in both clang and GCC. See a live example .
source share