<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62225>62225</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang: Construction of subobject of member 'Y' of union with active member 'X' is not allowed in a constant expression
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alexkaratarakis
      </td>
    </tr>
</table>

<pre>
    Min repro:
```cpp
#include <memory>

union MyUnion
{
    char dummy_{};
    int data_[50];
};

constexpr int test()
{
    MyUnion my_union{};
    std::construct_at(my_union.data_ + 1, 999);
    return 5;
}

int main()
{
    static_assert(test() > 0);
}
```

`clang` rejects the above code with:
```
<source>:19:19: error: static assertion expression is not an integral constant expression
    static_assert(test() > 0);
 ^~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/bits/stl_construct.h:97:14: note: construction of subobject of member 'data_' of union with active member 'dummy_' is not allowed in a constant expression
    { return ::new((void*)__location) _Tp(std::forward<_Args>(__args)...); }
 ^
<source>:12:5: note: in call to 'construct_at(&my_union.data_[1], 999)'
    std::construct_at(my_union.data_ + 1, 999);
 ^
<source>:19:19: note: in call to 'test()'
    static_assert(test() > 0);
                  ^
1 error generated.
```

However, `gcc` and `msvc` accept the above code.

Demo: https://godbolt.org/z/EYvsWdbsr

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVcuu2zYQ_Rp6Q1iQRtZroYXte41usmvRZiVQ1MRmQ5ECSdnXXfTbi7H80H0kSIoIAsXnzOGZOSPhvdobxJplG5Y9LcQYDtbVQuPLV-FEEE58VX7R2u5cf1KGOxycZemaxU8sXrM8nl45DNcZSJWReuyQs3TbY2_dmaXP18VLOxplDf90_oO-14ViM3U451wehOPd2PfnhuaLJ5bOVpUJv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