<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62988>62988</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Writing in constant expression to inactive union member via reference results in error
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
The following program:
```
constexpr int f()
{
union {
int x{0};
char y;
};
auto & z = y;
z = 1;
x = 0;
return x;
}
static_assert( f() == 0 );
```
is accepted by GCC and MSVC. But Clang complains:
```
assignment to member 'y' of union with active member 'x' is not allowed in a constant expression
```
Online demo: https://gcc.godbolt.org/z/EsnEsTKP4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0kk2PmzAQhn-NuYw2AkP4OHDYJEsPVdVKXbXHytgDuDJ2ZA-7yf76yiT7qS1CYL96PeN5ZkQIerSILdvu2PaQiIUm59sOlU96p87t_YQwOGPco7YjHL0bvZhZfsvSA0tvWZle33UrnQ2Ep6MHbQkGxmvGm6uz2l0WAACL1c7CqxTdJ1btUlYdWP7GGB85CQ_nd_JHm1jIAeMlPAHLDx_MFy171U6rkL4zeaTFWzi9iDHFZbF-AwnS8o8IAT0xXj8XF0Ot0SBW-nL4PRYdQEiJR0IF_Rm-7PcgrIJvP3_tN7BbCPZG2BGkm49GaBv-h_fSrBktATmYce7RA-PVmfEK3HDF-qhpAiFJP-Abzyl6dADrCERsJyrQFgSsPROWIPYNQ9DOfpr8uzXaIiicHctvYSI6rhflHePdKOVmdKp3hjbOj4x3T4x3d8HehfuvP4pEtblq8kYk2GZlvc3LOuNpMrVCZnLIUKZ1Myi1LWRfiHooMyVkpfJGJrrlKc_TLW-yvKiLdIN8m6syK9Imk70QFStSnIU2G2Me5pg70SEs2Ja8qevEiB5NeB5u30bTTb-MgRWp0YHC6zHSZLD97TXFQdf2MzARu7ZXthfaV8IPWoDHAT1aieAxLIZCjILeO58s3rQfiGmaln4j3cx4Fy9x_d0cvfuLkhjv1kIC491ay78AAAD__9vDFvE">