<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136559>136559</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang treats nested classes as non-default-constructible if they have member intializers, until the end of the outer class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HolyBlackCat
</td>
</tr>
</table>
<pre>
This is the same issue as described in this [very old stackoverflow question](https://stackoverflow.com/q/17430377/2752075).
https://gcc.godbolt.org/z/rP5YvqGfP
```cpp
#include <variant>
struct A
{
struct X
{
int x = 10;
int y = 20;
};
struct Y
{
std::variant<X /*, ...*/> var; // error: call to implicitly-deleted default constructor of 'A::Y'
};
};
int main()
{
A::Y y;
}
```
This compiles on GCC and MSVC. But Clang threats `std::variant<X>` as not default-constructible (because it first checks the default-constructibility of `X` when the variant is declared, and it doesn't consider it to be default-constructible at that point because it has default member initializers and no user-declared default ctor).
GCC used to fail on this too, but it has since been fixed. So presumably there's no technical reason why Clang couldn't accept this as well?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVMFu4zgM_RrlQsRQpDhODj4k6Xj2ssAAs1i0R1miY20VKZXodDxfv5CdNu2gRYFYlEg-vkdSpWRPHrFm5YGVDws1UB9i_Vdw48Ep_XxUtGiDGet_epvAJqAeIakzgk1pQFAJDCYdbYsGrAfKz1h5uGIcITgDiZR-DleMnQuv8DJgIhs8Kx-Y2PZEl8TknomGiebTy0KHMxPNCxPNqlpLLquKiUZUpeBVycSuYHzP-P5zhJPWxSmYNjgqQjwx0fxmook_yqfry_fux-zCNnz-15dLPgppvXaDQWDyeFXRKk9MfpsfJ4qDJpj8qgPjewCAm_Hxdrxf5D_rCX4Bkw-w4kxON9k0TibxZprcHubD56hPX0ZNZHKVcv8O8PgIU9F7Jo5QFMX01TD5Da4qMnmYbxvAGENkcg9aOQcUwJ4vzmpL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