[llvm-dev] reinterpret_cast of pointer-to-member (original) (raw)

Deep Majumder via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 3 07:10:58 PST 2021


Hi everyone, I am working on a patch that involves reinterpret_cast of pointer to member. Working on Godbolt, it seems that the casts don't always make sense. Take a look at https://godbolt.org/z/6E7aoK. Both c and cs are supposed to point to the same field. However, c has the wrong offset (12) while cs has the right offset (0). This can be seen from the return value also (returns 16 instead of the expected 29). So my query is: are reinterpret_cast on pointer-to-member considered undefined behaviour? Because different optimisation levels give different answers (try -O2). Warm regards, Deep -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210303/8ea93318/attachment.html>



More information about the llvm-dev mailing list