1 // RUN: %clang_cc1 -Wno-pointer-to-int-cast -fsyntax-only -verify %s
2 // PR3459
3 struct bar {
4   char n[1];
5 };
6 
7 struct foo {
8   char name[(int)&((struct bar *)0)->n];
9   char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}}
10 };
11 
12 // PR3430
13 struct s {
14   struct st {
15     int v;
16   } *ts;
17 };
18 
19 struct st;
20 
foo()21 int foo() {
22   struct st *f;
23   return f->v + f[0].v;
24 }
25 
26 // PR3642, PR3671
27 struct pppoe_tag {
28  short tag_type;
29  char tag_data[];
30 };
31 struct datatag {
32   struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}}
33   char data;
34 };
35 
36 
37 // PR4092
38 struct s0 {
39   char a;  // expected-note {{previous declaration is here}}
40   char a;  // expected-error {{duplicate member 'a'}}
41 };
42 
f0(void)43 struct s0 f0(void) {}
44 
45 // <rdar://problem/8177927> - This previously triggered an assertion failure.
46 struct x0 {
47   unsigned int x1;
48 };
49 
50 // rdar://problem/9150338
51 static struct test1 { // expected-warning {{'static' ignored on this declaration}}
52   int x;
53 };
54 const struct test2 { // expected-warning {{'const' ignored on this declaration}}
55   int x;
56 };
57 inline struct test3 { // expected-error {{'inline' can only appear on functions}}
58   int x;
59 };
60 
61 struct hiding_1 {};
62 struct hiding_2 {};
test_hiding()63 void test_hiding() {
64   struct hiding_1 *hiding_1();
65   extern struct hiding_2 *hiding_2;
66   struct hiding_1 *p = hiding_1();
67   struct hiding_2 *q = hiding_2;
68 }
69 
70 struct PreserveAttributes {};
71 typedef struct __attribute__((noreturn)) PreserveAttributes PreserveAttributes_t; // expected-warning {{'noreturn' attribute only applies to functions and methods}}
72 
73 // PR46255
74 struct FlexibleArrayMem {
75   int a;
76   int b[];
77 };
78 
79 struct FollowedByNamed {
80   struct FlexibleArrayMem a; // expected-warning {{field 'a' with variable sized type 'struct FlexibleArrayMem' not at the end of a struct or class is a GNU extension}}
81   int i;
82 };
83 
84 struct FollowedByUnNamed {
85   struct FlexibleArrayMem a; // expected-warning {{field 'a' with variable sized type 'struct FlexibleArrayMem' not at the end of a struct or class is a GNU extension}}
86   struct {
87     int i;
88   };
89 };
90 
91 struct InAnonymous {
92   struct { // expected-warning-re {{field '' with variable sized type 'struct InAnonymous::(anonymous at {{.+}})' not at the end of a struct or class is a GNU extension}}
93 
94     struct FlexibleArrayMem a;
95   };
96   int i;
97 };
98 struct InAnonymousFollowedByAnon {
99   struct { // expected-warning-re {{field '' with variable sized type 'struct InAnonymousFollowedByAnon::(anonymous at {{.+}})' not at the end of a struct or class is a GNU extension}}
100 
101     struct FlexibleArrayMem a;
102   };
103   struct {
104     int i;
105   };
106 };
107 
108 // This is the behavior in C++ as well, so making sure we reproduce it here.
109 struct InAnonymousFollowedByEmpty {
110   struct FlexibleArrayMem a; // expected-warning {{field 'a' with variable sized type 'struct FlexibleArrayMem' not at the end of a struct or class is a GNU extension}}
111   struct {};
112 };
113