Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 2 | struct 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 | |
| 24 | void test_unqual_references(struct X x, const struct X xc) { |
| 25 | x.i = 0; |
| 26 | x.f = 0.0; |
| 27 | x.f2 = x.f; |
| 28 | x.d = x.f; |
| 29 | x.f3 = 0; // expected-error{{no member named 'f3'}} |
| 30 | x.a = 0; |
| 31 | |
| 32 | xc.d = 0.0; // expected-error{{read-only variable is not assignable}} |
| 33 | xc.f = 0; // expected-error{{read-only variable is not assignable}} |
| 34 | xc.a = 0; // expected-error{{read-only variable is not assignable}} |
| 35 | } |
| 36 | |
| 37 | |
| 38 | struct Redecl { |
| 39 | int x; // expected-note{{previous declaration is here}} |
| 40 | struct y { }; |
| 41 | |
| 42 | union { |
| 43 | int x; // expected-error{{member of anonymous union redeclares 'x'}} |
| 44 | float y; |
| 45 | double z; // expected-note{{previous declaration is here}} |
| 46 | double zz; // expected-note{{previous declaration is here}} |
| 47 | }; |
| 48 | |
| 49 | int z; // expected-error{{duplicate member 'z'}} |
Chris Lattner | 1829a6d | 2009-02-23 22:00:08 +0000 | [diff] [blame] | 50 | void zz(); // expected-error{{duplicate member 'zz'}} |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 53 | union { // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 54 | int int_val; |
| 55 | float float_val; |
| 56 | }; |
| 57 | |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 58 | static union { // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 59 | int int_val2; |
| 60 | float float_val2; |
| 61 | }; |
| 62 | |
| 63 | void f() { |
| 64 | int_val2 = 0; // expected-error{{use of undeclared identifier}} |
| 65 | float_val2 = 0.0; // expected-error{{use of undeclared identifier}} |
| 66 | } |
| 67 | |
| 68 | void g() { |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 69 | union { // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 70 | int i; |
| 71 | float f2; |
| 72 | }; |
| 73 | i = 0; // expected-error{{use of undeclared identifier}} |
| 74 | f2 = 0.0; // expected-error{{use of undeclared identifier}} |
| 75 | } |
| 76 | |
| 77 | // <rdar://problem/6483159> |
| 78 | struct s0 { union { int f0; }; }; |
| 79 | |
| 80 | // <rdar://problem/6481130> |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 81 | typedef struct { }; // expected-warning{{declaration does not declare anything}} |
Daniel Dunbar | c8d8fa9 | 2009-02-27 17:07:01 +0000 | [diff] [blame] | 82 | |
| 83 | // PR3675 |
| 84 | struct s1 { |
| 85 | int f0; // expected-note{{previous declaration is here}} |
| 86 | union { |
| 87 | int f0; // expected-error{{member of anonymous union redeclares 'f0'}} |
| 88 | }; |
| 89 | }; |
Douglas Gregor | a71c129 | 2009-03-06 23:06:59 +0000 | [diff] [blame] | 90 | |
Douglas Gregor | e950d4b | 2009-03-06 23:28:18 +0000 | [diff] [blame] | 91 | // PR3680 |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 92 | struct {}; // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | e950d4b | 2009-03-06 23:28:18 +0000 | [diff] [blame] | 93 | |
| 94 | struct s2 { |
| 95 | union { |
| 96 | int a; |
| 97 | } |
| 98 | }; // expected-error{{expected member name or ';' after declaration specifiers}} |
John McCall | 64f7e25 | 2010-01-13 22:07:44 +0000 | [diff] [blame] | 99 | |
| 100 | // Make sure we don't a.k.a. anonymous structs. |
| 101 | typedef struct { |
| 102 | int x; |
| 103 | } a_struct; |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 104 | int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' with an expression of incompatible type 'a_struct'}} |