Open MitalAshok opened 2 months ago
@llvm/issue-subscribers-clang-frontend
Author: Mital Ashok (MitalAshok)
@llvm/issue-subscribers-c-20
Author: Mital Ashok (MitalAshok)
CWG2658 is perhaps related, but that case is different.
The resolution doesn't seem to make copying a partially living array in a union valid in constant evaluation. IIUC, in constant evaluation when the copy construction is trivial, T u2 = u1;
is considered to be decomposed to
T u2{.arr{u1.arr[0], u1.arr[1], u1.arr[2], u1.arr[3]}};
And then it's UB to read u1.arr[1]
etc. which are dead?
I guess it would be better to submit a CWG issue for this.
Edit: Not A Defect??! So Clang seems to be correct here.
Since C++20 P1331R2, a constructor call doesn't need to leave all of an object initialized.
Take this https://godbolt.org/z/63vo7MP9o:
Clang errors on
f<S2>()
:It should not be a problem that the entirety of
'arr'
isn't initialized (it was fine with the non-trivial copy constructor ofS1
and with the unionU
)GCC accepts this. MSVC does not accept
f<U>()
orf<S2>()
.