<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60711>60711</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Move construction clobbers data through [[no_unique_data]]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
danakj
</td>
</tr>
</table>
<pre>
Godbolt: https://godbolt.org/z/e96axcv1b
```cpp
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
struct S2 {
uint64_t a;
};
struct S : public S2 {
S(uint8_t b, uint64_t a) : S2(a), b(b) {}
uint8_t b;
// 3 bytes padding.
};
static_assert(sizeof(S) == 16);
union U {
U() {}
[[no_unique_address]] S s;
};
static_assert(sizeof(U) == 16);
struct D {
D(uint8_t i) : i(i) {}
[[no_unique_address]] U u;
uint8_t i;
};
static_assert(sizeof(D) == 16);
int main() {
D d(1u);
std::cout << (int)d.i << "\n"; // Prints 1
// Regular construction into `D::u` doesn't touch `D::i`. Good.
new (&d.u.s) S(2, 3);
std::cout << (int)d.i << "\n"; // Prints 1
S s(4, 5);
// Move construction into `D::u` overwrites `D::i`. Bad.
new (&d.u.s) S(std::move(s));
std::cout << (int)d.i << "\n"; // Prints 0
return d.i;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU2P2zYQ_TWjyyACNbRl-aDDelXnVKDoYs8GRdI2U5l0-eE0-fUFJW_8lWDTQwMsVtaM5s17TzOiCMHsrNYtzFcw7wqR4t75Vgkr_vpU9E59aT861bshAn_CfYzHAPwJaA203k2J0vkd0Por0Fova_GPPFU9sA7Y0_l_zaY_eTyeI8SNlUNSGoE_h6iMjeUe-G83ZTcPGRei1-JweegOwxu7-0HypGV0_g4-RJ9kxBdCWKymECJiMjbWs01EAfwchkV3-X1Ti9mTY-oHIx-AXoCaDNZsIvZAz9fItBwrXwioyXc53QM1_ZhZrHLHG0YTyBsJnOxHjv2XqAMehVLG7spHuiGKaORGhKB9BGqC-ardFqh5mTh0wDus6kzhVmGyxll8vZX0CtR8j-E4OivrNsmav5PeCKW8DgHmHcw7fMHwXSt_yO31HW5n97srct2V2ebNXgPUmHu-P8v6FdPF76u3YP6blu4dLcZGPAhjr5z91rJDBdRU6boqx0NUeQX5k3Qp5vkG_oxZq41AS1WaS4xg_mzzha_wbWr-8MbGgNWDH1P6T71Lg_AonZ2MzoNgbHQINeumxglqhsrpYIEWEaNLcn-VNlCzEj86p8oLvNWfcVRZqzKVIavNK0J59vkvkphHkZpZbjm_b3ku_d2d9Pva3Un7z97k5buXvRI_ofqbvoM76Xw_fgT-Dw_YBdDrmLxFVd7O8O03ulAtV0u-FIVuq3pRczarmlmxb6mRTFaMyeW2XlR1o-ZsxknSQqtKbZfbwrTEiDOqeFUzzmalkmJJ1XZbV3PBpF7CjOmDMEM5DKdDPjQKE0LSbc0WVVUMotdDGI8homzbmBy1dYVvc82HPu0CzNhgQgwXlGjioNvHFycH1_faB1QiCox779Ju_7D2OTntfJH80N6dcCbuU19KdwBa54bny4ejd5-0jEDrkWYAWo8y_g0AAP__82_6-Q">