summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/anonymous-struct-union.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-12 22:49:06 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-12 22:49:06 +0000
commitc6f58fe266948394b952ae6336412eb20443d6dd (patch)
tree67bfdb99392885ac057dada9f6fc430eb7a1c633 /clang/test/Sema/anonymous-struct-union.c
parentdd0efa8aad3373ba74d18ad7aac1bb9671bd4b60 (diff)
downloadbcm5719-llvm-c6f58fe266948394b952ae6336412eb20443d6dd.tar.gz
bcm5719-llvm-c6f58fe266948394b952ae6336412eb20443d6dd.zip
Implement support for anonymous structs and unions in C. Both C and
C++ handle anonymous structs/unions in the same way. Addresses several bugs: <rdar://problem/6259534> <rdar://problem/6481130> <rdar://problem/6483159> The test case in PR clang/1750 now passes with -fsyntax-only, but CodeGen for inline assembler still fails. llvm-svn: 62112
Diffstat (limited to 'clang/test/Sema/anonymous-struct-union.c')
-rw-r--r--clang/test/Sema/anonymous-struct-union.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/clang/test/Sema/anonymous-struct-union.c b/clang/test/Sema/anonymous-struct-union.c
new file mode 100644
index 00000000000..72790c9abb4
--- /dev/null
+++ b/clang/test/Sema/anonymous-struct-union.c
@@ -0,0 +1,82 @@
+// RUN: clang -fsyntax-only -verify %s
+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'}}
+ void zz(); // expected-error{{duplicate member 'zz'}} \
+ // expected-error{{field 'zz' declared as a function}}
+};
+
+union { // expected-error{{anonymous unions must be struct or union members}}
+ int int_val;
+ float float_val;
+};
+
+static union { // expected-error{{anonymous unions must be struct or union members}}
+ 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() {
+ union { // expected-error{{anonymous unions must be struct or union members}}
+ 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>
+typedef struct { }; // expected-error{{declaration does not declare anything}}
OpenPOWER on IntegriCloud