You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stop diagnosing member and array access in offsetof as an extension
This was a mistake from e7300e7
(https://reviews.llvm.org/D133574) caused by us accidentally tracking
an older copy of the C DR list for DR496. The text in
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_496 makes
it clear that subobjects are allowed, which means member and array
access expressions are allowed.
This backs out the changes from the previous commit that relate to this
diagnostic.
(cherry picked from commit 63d6b8b)
Copy file name to clipboardExpand all lines: clang/test/C/drs/dr4xx.c
+4-10Lines changed: 4 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -331,19 +331,13 @@ void dr496(void) {
331
331
structB { structAa; };
332
332
structC { structAa[1]; };
333
333
334
-
/* The standard does not require either of these examples to work, but we
335
-
* support them just the same. The first one is invalid because it's
336
-
* referencing a member of a different struct, and the second one is invalid
337
-
* because it references an array of another struct. Clang calculates the
338
-
* correct offset to each of those fields.
339
-
*/
340
-
_Static_assert(__builtin_offsetof(structB, a.n) ==0, ""); /* expected-warning {{using a member access expression within '__builtin_offsetof' is a Clang extension}} */
334
+
/* Array access & member access expressions are now valid. */
/* First int below is for 'n' and the second int is for 'a[0]'; this presumes
342
337
* there is no padding involved.
343
338
*/
344
-
_Static_assert(__builtin_offsetof(structB, a.a[1]) ==sizeof(int) +sizeof(int), ""); /* expected-warning {{using a member access expression within '__builtin_offsetof' is a Clang extension}}
345
-
expected-warning {{using an array subscript expression within '__builtin_offsetof' is a Clang extension}}
0 commit comments