[libcxx-commits] [libcxx] [libc++][ranges][abi-break] Fix `movable_box` overwriting memory of data that lives in the tail padding (PR #71314)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Nov 5 13:05:34 PST 2023
huixie90 wrote:
> Is an empty object allowed to access it's padding? If yes, we have to remove `[[no_unique_address]]` in all cases.
I don't know the answer, and if the following code is valid, then yes we cannot use EBO or `no_unqiue_address`
```
struct e {
e(){
std::memset(this, 0x00, sizeof(e));
}
};
struct x :e {
bool b = true;
void foo() {
std::destroy_at(std::addressof(static_cast<e&>(*this)));
std::construct_at(std::addressof(static_cast<e&>(*this)));
}
};
struct y {
[[no_unique_address]] e e1;
bool b= true;
void foo() {
std::destroy_at(std::addressof(e1));
std::construct_at(std::addressof(e1));
}
};
static_assert(sizeof(x) == sizeof(bool));
static_assert(sizeof(y) == sizeof(bool));
int main(){
x x1;
assert(x1.b);
x1.foo();
assert(x1.b); // boom
y y1;
assert(y1.b);
y1.foo();
assert(y1.b); // boom
}
```
https://github.com/llvm/llvm-project/pull/71314
More information about the libcxx-commits
mailing list