-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Clang] Fix missing diagnostic for non-standard layout type in offsetof
#65246
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,9 @@ struct Derived2 : public Base1, public Base2 { | |
int z; | ||
}; | ||
|
||
int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; | ||
int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; | ||
int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; | ||
int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems like an improvement in diagnostic behavior. |
||
int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}} | ||
int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}} | ||
|
||
// offsetof referring to anonymous struct in base. | ||
// PR7769 | ||
|
@@ -66,7 +66,8 @@ struct foo { | |
struct bar : public foo { | ||
}; | ||
|
||
int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1]; | ||
int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1]; // expected-warning{{offset of on non-POD type 'bar'}} | ||
|
||
|
||
struct LtoRCheck { | ||
int a[10]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,12 @@ struct __libcpp_datasizeof { | |
}; | ||
#endif | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional : Can you add a brief comment/note that why warnings are suppressed here?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thanks |
||
// _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is UB in that case, but GCC and Clang allow | ||
// the use as an extension. | ||
_LIBCPP_DIAGNOSTIC_PUSH | ||
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof") | ||
static const size_t value = offsetof(_FirstPaddingByte<>, __first_padding_byte_); | ||
_LIBCPP_DIAGNOSTIC_POP | ||
}; | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this diagnostic is an improvement over the status quo.