Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / C / C2x / n2350.c
blob2f738488a374270700ceeb9afb5e635ac6579b49
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
14 int simple(void) {
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}}
18 int a;
19 struct B // expected-warning {{defining a type within '__builtin_offsetof' is a Clang extension}}
21 int c;
22 int d;
23 } x;
24 }, a);
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}}
31 int a;
32 int b;
33 }, a);
36 int struct_in_second_param(void) {
37 struct A {
38 int a, b;
39 int x[20];
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)
48 int macro(void) {
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}}
52 int a;
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
56 int c;
57 int d;
58 } x;
59 }, a);
62 #undef offsetof
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}}
70 int a;
71 int b;
72 }, a);