| Issue |
173167
|
| Summary |
[Clang++] Is code valid if you perform reinterpret_cast on objects that are not pointer-convertible?
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
safocl
|
there is:
```cpp
struct SlangUUID
{
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
};
bool foo(const SlangUUID& aIn, const SlangUUID& bIn)
{
typedef uint32_t CmpType;
union GuidCompare
{
SlangUUID guid;
CmpType data[sizeof(SlangUUID) / sizeof(CmpType)];
};
const CmpType* a = reinterpret_cast<const GuidCompare&>(aIn).data;
const CmpType* b = reinterpret_cast<const GuidCompare&>(bIn).data;
return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3])) == 0;
}
```
Will Clang++ handle this code normally, or will punning not be applied here and undefined behavior will occur?
and will the reinterpret_cast itself be perceived without exhibiting undefined behavior?
original:
https://github.com/shader-slang/slang/blob/25c1c6e5e08d3cb618c847e1d4dc24eb003bc199/include/slang-com-helper.h#L99
https://github.com/shader-slang/slang/blob/25c1c6e5e08d3cb618c847e1d4dc24eb003bc199/include/slang.h#L1265
standard:
https://eel.is/c++draft/basic.compound#5
https://eel.is/c++draft/conv.qual#2
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs