Creating the objects in storage other than “array of N unsigned char” and access to it throught pointer to containing object.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I see code:
```cpp
struct S2 {
int i;
};
struct S {
uint64_t data[sizeof(S2)];
};
S s{};
new(reinterpret_cast(&s)) S2{};
auto i = reinterpret_cast(&s)->i;
```
This creates objects in the memory other than _“array of N unsigned char”_ (or _“array of N std::byte”_) and accessing them through a pointer of a non-_pointer-interconvertible_ type.
However, does this not violate the established acceptable storage variants and the _pointer-interconvertible_ rules ([[intro.object#3]](https://eel.is/c++draft/intro.object#3), [[basic.life#9]](https://eel.is/c++draft/basic.life#9) and [[basic.compound#5]](https://eel.is/c++draft/basic.compound#5))?
Shouldn't there be `unsigned char data[];` here?
https://github.com/llvm/llvm-project/blob/db5cd626b97a887cd237f9be9372cd3750fc7a02/libunwind/include/libunwind.h#L178
https://github.com/llvm/llvm-project/blob/52a880d30ba6cba38579ad7f51289d9ebe0c3719/libunwind/src/libunwind.cpp#L86
Shouldn't there be `cursor->data` here (or, alternatively, invoke std::launder)?
https://en.cppreference.com/w/cpp/utility/launder.html#Example
[[expr.add#6]](https://eel.is/c++draft/expr.add#6)
> For addition or subtraction, if the expressions P or Q have type “pointer to cv T”, where T and the array element type are not [similar](https://eel.is/c++draft/conv.qual#def:similar_types), the behavior is undefined[.](https://eel.is/c++draft/expr.add#6.sentence-1)
https://github.com/llvm/llvm-project/blob/e56161ef9841d61ea06e6b0a79e195e9a84addb1/libunwind/src/UnwindCursor.hpp#L2119
Contributor guide
Assessment
This issue has not been assessed yet.