blob: c33bc52971e76983fb54a4d66fb475b0aace2a80 [file] [log] [blame]
Fariborz Jahanianffc120a2014-08-26 21:10:47 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorc6f58fe2009-01-12 22:49:06 +00002struct X {
3 union {
4 float f3;
5 double d2;
6 } named;
7
8 union {
9 int i;
10 float f;
11
12 union {
13 float f2;
14 double d;
15 };
16 };
17
18 struct {
19 int a;
20 float b;
21 };
22};
23
24void test_unqual_references(struct X x, const struct X xc) {
Richard Trieuaf7d76c2015-04-11 01:53:13 +000025 // expected-note@-1 3{{variable 'xc' declared const here}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000026 x.i = 0;
27 x.f = 0.0;
28 x.f2 = x.f;
29 x.d = x.f;
30 x.f3 = 0; // expected-error{{no member named 'f3'}}
31 x.a = 0;
32
Richard Trieuaf7d76c2015-04-11 01:53:13 +000033 xc.d = 0.0; // expected-error{{cannot assign to variable 'xc' with const-qualified type 'const struct X'}}
34 xc.f = 0; // expected-error{{cannot assign to variable 'xc' with const-qualified type 'const struct X'}}
35 xc.a = 0; // expected-error{{cannot assign to variable 'xc' with const-qualified type 'const struct X'}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000036}
37
38
39struct Redecl {
40 int x; // expected-note{{previous declaration is here}}
David Majnemer8f0ed912014-08-11 07:29:54 +000041 struct y { }; // expected-warning{{declaration does not declare anything}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000042
43 union {
44 int x; // expected-error{{member of anonymous union redeclares 'x'}}
45 float y;
46 double z; // expected-note{{previous declaration is here}}
47 double zz; // expected-note{{previous declaration is here}}
48 };
49
50 int z; // expected-error{{duplicate member 'z'}}
Chris Lattnerd13b8b52009-02-23 22:00:08 +000051 void zz(); // expected-error{{duplicate member 'zz'}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000052};
53
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000054union { // expected-warning{{declaration does not declare anything}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000055 int int_val;
56 float float_val;
57};
58
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000059static union { // expected-warning{{declaration does not declare anything}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000060 int int_val2;
61 float float_val2;
62};
63
64void f() {
65 int_val2 = 0; // expected-error{{use of undeclared identifier}}
66 float_val2 = 0.0; // expected-error{{use of undeclared identifier}}
67}
68
69void g() {
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000070 union { // expected-warning{{declaration does not declare anything}}
Douglas Gregorc6f58fe2009-01-12 22:49:06 +000071 int i;
72 float f2;
73 };
74 i = 0; // expected-error{{use of undeclared identifier}}
75 f2 = 0.0; // expected-error{{use of undeclared identifier}}
76}
77
78// <rdar://problem/6483159>
79struct s0 { union { int f0; }; };
80
81// <rdar://problem/6481130>
Richard Smithb1402ae2013-03-18 22:52:47 +000082typedef struct { }; // expected-warning{{typedef requires a name}}
Daniel Dunbar8d422812009-02-27 17:07:01 +000083
84// PR3675
85struct s1 {
86 int f0; // expected-note{{previous declaration is here}}
87 union {
88 int f0; // expected-error{{member of anonymous union redeclares 'f0'}}
89 };
90};
Douglas Gregor2e7cba62009-03-06 23:06:59 +000091
Douglas Gregord9f92e22009-03-06 23:28:18 +000092// PR3680
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000093struct {}; // expected-warning{{declaration does not declare anything}}
Douglas Gregord9f92e22009-03-06 23:28:18 +000094
95struct s2 {
96 union {
97 int a;
Carl Norum58d489f2011-03-07 22:57:45 +000098 } // expected-warning{{expected ';' at end of declaration list}}
Douglas Gregord9f92e22009-03-06 23:28:18 +000099}; // expected-error{{expected member name or ';' after declaration specifiers}}
John McCall02bc54d2010-01-13 22:07:44 +0000100
101// Make sure we don't a.k.a. anonymous structs.
102typedef struct {
103 int x;
104} a_struct;
Douglas Gregorb10646d2010-04-09 17:53:29 +0000105int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' with an expression of incompatible type 'a_struct'}}
Eli Friedmana7679412012-02-07 05:00:47 +0000106
107// This example comes out of the C11 standard; make sure we don't accidentally reject it.
108struct s {
109 struct { int i; };
110 int a[];
111};
Aaron Ballman260995b2014-10-15 16:58:18 +0000112
113// PR20930
114struct s3 {
115 struct { int A __attribute__((deprecated)); }; // expected-note {{'A' has been explicitly marked deprecated here}}
116};
117
118void deprecated_anonymous_struct_member(void) {
119 struct s3 s;
120 s.A = 1; // expected-warning {{'A' is deprecated}}
121}