<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56313>56313</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error with valid defaulted default constructor involving anonymous union
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jensmaurer
</td>
</tr>
</table>
<pre>
Test case:
```
struct A {
A() { }
};
struct V {
V() { };
~V() { }
};
struct S {
S();
~S() {}
union {
A a = {};
V v;
};
};
S::S() = default;
```
Result:
```
x.cc:22:4: error: defaulting this default constructor would delete it after its first declaration
S::S() = default;
^
```
The error goes away if `= default` is replaced with `{}`.
The error message is incorrect, because none of the items in [class.default.ctor] p2 applies. In particular, p2.2 does not apply because S::a has a default member initializer.
Related gcc bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106150
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNU8GOmzAQ_Rq4jIocE0hz4JBtdqVem9VeK2MG8MpgZJuk2a_vGJLNkm6rSmBmPDPPb96Y0lTn4hmdBykcRukuYvuI7aKcXZ7Jdd6O0sMOos3DvAMAu4h_jfg27NG7vxSSkV5yFrUvi9qXu9r0Foo2j_fRvyAv8A8L_MOMcId7uOHeYK_xsVemX4BQiyAgSvfXgvRj7AWOS_gP9P6gegjKprt3AoRZYS1G7W-JS8nn9Qe6KefzsfxKpKQY57Ss6QW01thgXMBV34Bvlbv6IE0_62UsnMyoK4po9AjKg6g9WjIc1MrShahQamGFJ1n-u4kgRPb4j4aeW5xZQmPQgTiJM6gaQtYHuJwBkbY4aCGxgpPy7ZQyjyFnyeeQHTonGgy1qpfGWpQ-4t-gRClGh9CbHsHUJEloGLuQRnwfqE_nksvhSRAnyvYwcBDDoBW6BL73MAjrlRxJkgA58IRDFVrojZ_yzu_HXHQS0Arq8F37DrsyCNwrr4RWb2iT5ai18NRsIyWUYxO6NzaMHlrvBxcw-RM9FE-afkyMbcijzDeltSDTteb0k_xENipKn1RFiq5YvspYXBVptU23IvbKayweJ7UmVY_EpLpSxOrTi6L6o9HHcJcEKXjuzOjmvyUerS7u2BHoWCbSdORofbx-vgzWvE7jeFLOjejIyPJ0lcZtwRjnq5KlebrdVjWWuJUoeZbXWY4lz7NYixK1K2hSNJdYFZwKWJ6y1ddsxbNks6mqDacysd4iW2fRmmEnlE7CwUGn2BYTBxLHUVAr590tSLNXTY94xRejb40tXrF3nRgt2nhiXEx0fwMLn4CL">