1 // RUN: %clang_cc1 -fsyntax-only -verify=silent %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=cpp -x c++ %s
3 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -verify %s
4 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c89 -verify %s
5 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c99 -verify %s
6 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c11 -verify %s
7 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c17 -verify %s
8 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c2x -verify %s
10 // silent-no-diagnostics
12 // Reject definitions in __builtin_offsetof
13 // https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
15 return __builtin_offsetof(struct A
// cpp-error {{'A' cannot be defined in a type specifier}} \
16 expected
-warning
{{defining a type within
'__builtin_offsetof' is a Clang extension
}}
19 struct B
// expected-warning {{defining a type within '__builtin_offsetof' is a Clang extension}}
27 int anonymous_struct(void) {
28 return __builtin_offsetof(struct // cpp-error-re {{'(unnamed struct at {{.*}})' cannot be defined in a type specifier}} \
29 expected
-warning
{{defining a type within
'__builtin_offsetof' is a Clang extension
}}
36 int struct_in_second_param(void) {
41 return __builtin_offsetof(struct A
, x
[sizeof(struct B
{int a
;})]); // cpp-error {{'B' cannot be defined in a type specifier}}
45 #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
49 return offsetof(struct A
// cpp-error {{'A' cannot be defined in a type specifier}} \
50 expected
-warning
2 {{defining a type within
'offsetof' is a Clang extension
}}
53 struct B
// verifier seems to think the error is emitted by the macro
54 // In fact the location of the error is "B" on the line above
64 #define offsetof(TYPE, MEMBER) (&((TYPE *)0)->MEMBER)
66 // no warning for traditional offsetof as a function-like macro
67 int * macro_func(void) {
68 return offsetof(struct A
// cpp-error {{'A' cannot be defined in a type specifier}}