-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing diagnostic for non-standard layout types in offsetof
#64619
Comments
CC @AaronBallman |
Interesting we do have llvm-project/clang/lib/Sema/SemaExpr.cpp Lines 16745 to 16753 in e6f18b7
I haven't debugged it to see why we don't catch this case. |
We only warn in evaluated context. I don't know if that make sense https://godbolt.org/z/MGTWofPxY |
It's been this way since it was added in 882211c in 2010. That said, I'm not certain why this should be issued only when evaluated at runtime. My guess is that it's a runtime diagnostic because the offset is expected to be used at runtime to offset into some memory buffer; so if you never reach that code, the fact that it's conditionally supported doesn't matter. But I'm not certain if that's an accurate guess -- I could not find a code review to see if this was explicitly discussed. |
I can see that reasoning be problematic, for example: void f() {
constexpr auto idx = offsetof(nonstandardlayout, foo);
loose_a_limb(idx);
} |
Yeah, basically 2010 predates thinking about |
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
For more instructions on how to submit a patch to LLVM, see our documentation. If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue. @llvm/issue-subscribers-good-first-issue |
Hi, I am new to LLVM and would like to try to see if this issue is still open. Could someone please set up an assignee for me? (I'll send a patch after the pull request migration is done) |
Great.
Done. |
Thank you |
`offsetof` Fixes llvm#64619 Clang warns diagnostic for non-standard layout types in `offsetof` only if they are in evaluated context. With this patch, you'll also get diagnostic if you use `offsetof` on non-standard layout types in any other contexts
Consider the following example (https://godbolt.org/z/o77v1nad9):
Only GCC warns that non-standard layout type is passed to
offsetof
, which is conditionally-supported.GCC issues it by default, whereas Clang, MSVC, and EDG doesn't even in pedantic modes (or
/W4
).I'm not sure what the solution should be, but I feel like there is a problem to solve.
The text was updated successfully, but these errors were encountered: