<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65143>65143</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Anonymous union members initialized with designated initializers does not compile inside template
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Clueliss
</td>
</tr>
</table>
<pre>
The following code fails to compile on at least clang-14,15,16:
```c++
struct Inner {
};
struct Outer {
union {
Inner inner;
};
};
template<typename>
void f() {
Outer x{.inner = {}};
}
int main() {
f<int>();
}
```
With the following message:
```
error: field designator (null) does not refer to any field in type 'Outer'
<source>:16:5: note: in instantiation of function template specialization 'f<int>' requested here
f<int>();
^
```
Removing the template on `f` resolves the error.
Godbolt: https://godbolt.org/z/Tod1oa1Gd
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0lEtv4j4QwD_N5DIqSuw8yCEHHqX6n_7SqtKenXgCXjk2azt06adfOYECbRdFA_G8fzNYeK_2hqiBYg3FNhFjOFjXbPRIWnmftFaem9cDYW-1tm_K7LGzkrAXSnsMFjs7HJUmtAZFQE3CB-y0MPunLAe2yYooSuArSLeQXmWZzk8HbB2f6dQHN3YB_zOGHEJ1OYVqC3x9732x-38M93aIiKNR1jwexc8cUUX5EQof4n7JEWg4ahEI-Cacj2TEQMCfZ93JKok9sCWw-jHZXNIfqNYLNXfBt5NFtf2c7qHA-U2ZgINQ5rvIPfCNMiHWMGm_xvpgOr_-VOGA4WFwA3kv9nSbxaMHOWcd8BX2irRESXEzRLAOgS3NqHUsSlryaGxARz25uADCnC8eymBkhcCqCQSw6pKIb7wdXTch5KtpHYqYydhIeBU9lfFBmKBEiCO0Pfaj6abf11GgP1KnhFbvsw2w6p5KhY5-j-QDSTyQowu7f4KbuBfP36KY5Q8a7CmCixg_qoiZy7SHMkVH3uoT-clgwre493-xsrU6xAYPIRx9BM92wHb7WbGwbg9s9w5s92plZkX2IhPZcFnzWiTUZGXN85pXeZYcmqKtO5FmWVH1uSgr3i7TshUVb6tlv5SdTFTDUsbTJc-yvCjydFFndSeWVc5Lxvq6I8hTGoTSC61PQ8ydKO9Hasoiy3miRUvaT9cAY4becFICY_FWcE30eWrHvYc81coHf4sSVNDUrIw158GO_vInHGhoyXlURoVpaCTxLe7kda9I3umcv23W9UZRxit5A5-MTjefOKpwGNtFZwdgu1jP5evp6Owv6gKw3dSFB7abuvwbAAD__7XOdz8">