anonymous-struct-union.c revision 4920f1ffb62b13b88e579476803c093f97f3e17f
1// RUN: clang -fsyntax-only -verify %s
2struct 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) {
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
38struct 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'}}
50  void zz(); // expected-error{{duplicate member 'zz'}} \
51            //  expected-error{{field 'zz' declared as a function}}
52};
53
54union { // expected-error{{anonymous unions must be struct or union members}}
55  int int_val;
56  float float_val;
57};
58
59static union { // expected-error{{anonymous unions must be struct or union members}}
60  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() {
70  union { // expected-error{{anonymous unions must be struct or union members}}
71    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>
82typedef struct { }; // expected-error{{declaration does not declare anything}}
83