[cfe-commits] r61860 - /cfe/trunk/test/SemaCXX/anonymous-union.cpp

Douglas Gregor dgregor at apple.com
Wed Jan 7 08:22:10 PST 2009


Author: dgregor
Date: Wed Jan  7 10:22:09 2009
New Revision: 61860

URL: http://llvm.org/viewvc/llvm-project?rev=61860&view=rev
Log:
Test case for anonymous unions in C++

Added:
    cfe/trunk/test/SemaCXX/anonymous-union.cpp

Added: cfe/trunk/test/SemaCXX/anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=61860&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/anonymous-union.cpp (added)
+++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Wed Jan  7 10:22:09 2009
@@ -0,0 +1,99 @@
+// RUN: clang -fsyntax-only -verify %s
+struct X {
+  union {
+    float f3;
+    double d2;
+  } named;
+
+  union {
+    int i;
+    float f;
+    
+    union {
+      float f2;
+      mutable double d;
+    };
+  };
+
+  void test_unqual_references();
+
+  struct {
+    int a;
+    float b;
+  };
+
+  void test_unqual_references_const() const;
+
+  mutable union { // expected-error{{anonymous union at class scope must not have a storage specifier}}
+    float c1;
+    double c2;
+  };
+};
+
+void X::test_unqual_references() {
+  i = 0;
+  f = 0.0;
+  f2 = f;
+  d = f;
+  f3 = 0; // expected-error{{use of undeclared identifier 'f3'}}
+  a = 0;
+}
+
+void X::test_unqual_references_const() const {
+  d = 0.0;
+  f2 = 0; // expected-error{{read-only variable is not assignable}}
+  a = 0; // expected-error{{read-only variable is not assignable}}
+}
+
+void test_unqual_references(X x, const 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;
+  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}}
+  class y { };
+
+  union {
+    int x; // expected-error{{member of anonymous union redeclares 'x'}}
+    float y;
+    double z; // FIXME: note here
+    double zz; // expected-note{{previous definition is here}}
+  };
+
+  int z; // FIXME: should complain here!
+  void zz(); // expected-error{{redefinition of 'zz' as different kind of symbol}}
+};
+
+union { // expected-error{{anonymous unions at namespace or global scope must be declared 'static'}}
+  int int_val;
+  float float_val;
+};
+
+static union {
+  int int_val2;
+  float float_val2;
+};
+
+void f() {
+  int_val2 = 0;
+  float_val2 = 0.0;
+}
+
+void g() {
+  union {
+    int i;
+    float f;
+  };
+  i = 0;
+  f = 0.0;
+}





More information about the cfe-commits mailing list