112 lines · c
1// RUN: %clang_cc1 -Wno-pointer-to-int-cast -fsyntax-only -verify %s2// PR34593struct bar {4 char n[1];5};6 7struct foo {8 char name[(int)&((struct bar *)0)->n]; // expected-warning {{folded to constant}}9 char name2[(int)&((struct bar *)0)->n - 1]; // expected-error {{array size is negative}}10};11 12// PR343013struct s {14 struct st {15 int v;16 } *ts;17};18 19struct st;20 21int foo(void) {22 struct st *f;23 return f->v + f[0].v;24}25 26// PR3642, PR367127struct pppoe_tag {28 short tag_type;29 char tag_data[];30};31struct 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// PR409238struct s0 {39 char a; // expected-note {{previous declaration is here}}40 char a; // expected-error {{duplicate member 'a'}}41};42 43struct s0 f0(void) {}44 45// This previously triggered an assertion failure.46struct x0 {47 unsigned int x1;48};49 50static struct test1 { // expected-warning {{'static' ignored on this declaration}}51 int x;52};53const struct test2 { // expected-warning {{'const' ignored on this declaration}}54 int x;55};56inline struct test3 { // expected-error {{'inline' can only appear on functions}}57 int x;58};59 60struct hiding_1 {};61struct hiding_2 {};62void test_hiding(void) {63 struct hiding_1 *hiding_1(void);64 extern struct hiding_2 *hiding_2;65 struct hiding_1 *p = hiding_1();66 struct hiding_2 *q = hiding_2;67}68 69struct PreserveAttributes {};70typedef struct __attribute__((noreturn)) PreserveAttributes PreserveAttributes_t; // expected-warning {{'noreturn' attribute only applies to functions and methods}}71 72// PR4625573struct FlexibleArrayMem {74 int a;75 int b[];76};77 78struct FollowedByNamed {79 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}}80 int i;81};82 83struct FollowedByUnNamed {84 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}}85 struct {86 int i;87 };88};89 90struct InAnonymous {91 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}}92 93 struct FlexibleArrayMem a;94 };95 int i;96};97struct InAnonymousFollowedByAnon {98 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}}99 100 struct FlexibleArrayMem a;101 };102 struct {103 int i;104 };105};106 107// This is the behavior in C++ as well, so making sure we reproduce it here.108struct InAnonymousFollowedByEmpty {109 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}}110 struct {};111};112