2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-01-13 06:49:06 +08:00
|
|
|
struct X {
|
|
|
|
union {
|
|
|
|
float f3;
|
|
|
|
double d2;
|
|
|
|
} named;
|
|
|
|
|
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
|
|
|
|
union {
|
|
|
|
float f2;
|
|
|
|
double d;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int a;
|
|
|
|
float b;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_unqual_references(struct X x, const struct X xc) {
|
|
|
|
x.i = 0;
|
|
|
|
x.f = 0.0;
|
|
|
|
x.f2 = x.f;
|
|
|
|
x.d = x.f;
|
|
|
|
x.f3 = 0; // expected-error{{no member named 'f3'}}
|
|
|
|
x.a = 0;
|
|
|
|
|
|
|
|
xc.d = 0.0; // expected-error{{read-only variable is not assignable}}
|
|
|
|
xc.f = 0; // expected-error{{read-only variable is not assignable}}
|
|
|
|
xc.a = 0; // expected-error{{read-only variable is not assignable}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct Redecl {
|
|
|
|
int x; // expected-note{{previous declaration is here}}
|
|
|
|
struct y { };
|
|
|
|
|
|
|
|
union {
|
|
|
|
int x; // expected-error{{member of anonymous union redeclares 'x'}}
|
|
|
|
float y;
|
|
|
|
double z; // expected-note{{previous declaration is here}}
|
|
|
|
double zz; // expected-note{{previous declaration is here}}
|
|
|
|
};
|
|
|
|
|
|
|
|
int z; // expected-error{{duplicate member 'z'}}
|
2009-02-24 06:00:08 +08:00
|
|
|
void zz(); // expected-error{{duplicate member 'zz'}}
|
2009-01-13 06:49:06 +08:00
|
|
|
};
|
|
|
|
|
2010-04-09 05:33:23 +08:00
|
|
|
union { // expected-warning{{declaration does not declare anything}}
|
2009-01-13 06:49:06 +08:00
|
|
|
int int_val;
|
|
|
|
float float_val;
|
|
|
|
};
|
|
|
|
|
2010-04-09 05:33:23 +08:00
|
|
|
static union { // expected-warning{{declaration does not declare anything}}
|
2009-01-13 06:49:06 +08:00
|
|
|
int int_val2;
|
|
|
|
float float_val2;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
int_val2 = 0; // expected-error{{use of undeclared identifier}}
|
|
|
|
float_val2 = 0.0; // expected-error{{use of undeclared identifier}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void g() {
|
2010-04-09 05:33:23 +08:00
|
|
|
union { // expected-warning{{declaration does not declare anything}}
|
2009-01-13 06:49:06 +08:00
|
|
|
int i;
|
|
|
|
float f2;
|
|
|
|
};
|
|
|
|
i = 0; // expected-error{{use of undeclared identifier}}
|
|
|
|
f2 = 0.0; // expected-error{{use of undeclared identifier}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <rdar://problem/6483159>
|
|
|
|
struct s0 { union { int f0; }; };
|
|
|
|
|
|
|
|
// <rdar://problem/6481130>
|
2013-03-19 06:52:47 +08:00
|
|
|
typedef struct { }; // expected-warning{{typedef requires a name}}
|
2009-02-28 01:07:01 +08:00
|
|
|
|
|
|
|
// PR3675
|
|
|
|
struct s1 {
|
|
|
|
int f0; // expected-note{{previous declaration is here}}
|
|
|
|
union {
|
|
|
|
int f0; // expected-error{{member of anonymous union redeclares 'f0'}}
|
|
|
|
};
|
|
|
|
};
|
2009-03-07 07:06:59 +08:00
|
|
|
|
2009-03-07 07:28:18 +08:00
|
|
|
// PR3680
|
2010-04-09 05:33:23 +08:00
|
|
|
struct {}; // expected-warning{{declaration does not declare anything}}
|
2009-03-07 07:28:18 +08:00
|
|
|
|
|
|
|
struct s2 {
|
|
|
|
union {
|
|
|
|
int a;
|
2011-03-08 06:57:45 +08:00
|
|
|
} // expected-warning{{expected ';' at end of declaration list}}
|
2009-03-07 07:28:18 +08:00
|
|
|
}; // expected-error{{expected member name or ';' after declaration specifiers}}
|
2010-01-14 06:07:44 +08:00
|
|
|
|
|
|
|
// Make sure we don't a.k.a. anonymous structs.
|
|
|
|
typedef struct {
|
|
|
|
int x;
|
|
|
|
} a_struct;
|
2010-04-10 01:53:29 +08:00
|
|
|
int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' with an expression of incompatible type 'a_struct'}}
|
2012-02-07 13:00:47 +08:00
|
|
|
|
|
|
|
// This example comes out of the C11 standard; make sure we don't accidentally reject it.
|
|
|
|
struct s {
|
|
|
|
struct { int i; };
|
|
|
|
int a[];
|
|
|
|
};
|