diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/CXX/class/class.union | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/CXX/class/class.union')
-rw-r--r-- | clang/test/CXX/class/class.union/p1.cpp | 125 | ||||
-rw-r--r-- | clang/test/CXX/class/class.union/p2-0x.cpp | 48 |
2 files changed, 173 insertions, 0 deletions
diff --git a/clang/test/CXX/class/class.union/p1.cpp b/clang/test/CXX/class/class.union/p1.cpp new file mode 100644 index 0000000..f344ae5 --- /dev/null +++ b/clang/test/CXX/class/class.union/p1.cpp @@ -0,0 +1,125 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void abort() __attribute__((noreturn)); + +class Okay { + int a_; +}; + +class Virtual { + virtual void foo() { abort(); } // expected-note 4 {{because type 'Virtual' has a virtual member function}} +}; + +class VirtualBase : virtual Okay { // expected-note 4 {{because type 'VirtualBase' has a virtual base class}} +}; + +class Ctor { + Ctor() { abort(); } // expected-note 4 {{because type 'Ctor' has a user-declared constructor}} +}; +class Ctor2 { + Ctor2(); // expected-note 3 {{because type 'Ctor2' has a user-declared constructor}} +}; +class CtorTmpl { + template<typename T> CtorTmpl(); // expected-note {{because type 'CtorTmpl' has a user-declared constructor}} +}; + +class CopyCtor { + CopyCtor(CopyCtor &cc) { abort(); } // expected-note 4 {{because type 'CopyCtor' has a user-declared copy constructor}} +}; + +// FIXME: this should eventually trigger on the operator's declaration line +class CopyAssign { // expected-note 4 {{because type 'CopyAssign' has a user-declared copy assignment operator}} + CopyAssign& operator=(CopyAssign& CA) { abort(); } +}; + +class Dtor { + ~Dtor() { abort(); } // expected-note 4 {{because type 'Dtor' has a user-declared destructor}} +}; + +union U1 { + Virtual v; // expected-error {{union member 'v' has a non-trivial copy constructor}} + VirtualBase vbase; // expected-error {{union member 'vbase' has a non-trivial copy constructor}} + Ctor ctor; // expected-error {{union member 'ctor' has a non-trivial constructor}} + Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}} + CtorTmpl ctortmpl; // expected-error {{union member 'ctortmpl' has a non-trivial constructor}} + CopyCtor copyctor; // expected-error {{union member 'copyctor' has a non-trivial copy constructor}} + CopyAssign copyassign; // expected-error {{union member 'copyassign' has a non-trivial copy assignment operator}} + Dtor dtor; // expected-error {{union member 'dtor' has a non-trivial destructor}} + Okay okay; +}; + +union U2 { + struct { + Virtual v; // expected-note {{because type 'U2::<anonymous struct}} + } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}} + struct { + VirtualBase vbase; // expected-note {{because type 'U2::<anonymous struct}} + } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}} + struct { + Ctor ctor; // expected-note {{because type 'U2::<anonymous struct}} + } m3; // expected-error {{union member 'm3' has a non-trivial constructor}} + struct { + Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous struct}} + } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}} + struct { + CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous struct}} + } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} + struct { + CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous struct}} + } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}} + struct { + Dtor dtor; // expected-note {{because type 'U2::<anonymous struct}} + } m6; // expected-error {{union member 'm6' has a non-trivial destructor}} + struct { + Okay okay; + } m7; +}; + +union U3 { + struct s1 : Virtual { // expected-note {{because type 'U3::s1' has a base class with a non-trivial copy constructor}} + } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}} + struct s2 : VirtualBase { // expected-note {{because type 'U3::s2' has a base class with a non-trivial copy constructor}} + } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}} + struct s3 : Ctor { // expected-note {{because type 'U3::s3' has a base class with a non-trivial constructor}} + } m3; // expected-error {{union member 'm3' has a non-trivial constructor}} + struct s3a : Ctor2 { // expected-note {{because type 'U3::s3a' has a base class with a non-trivial constructor}} + } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}} + struct s4 : CopyCtor { // expected-note {{because type 'U3::s4' has a base class with a non-trivial copy constructor}} + } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} + struct s5 : CopyAssign { // expected-note {{because type 'U3::s5' has a base class with a non-trivial copy assignment operator}} + } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}} + struct s6 : Dtor { // expected-note {{because type 'U3::s6' has a base class with a non-trivial destructor}} + } m6; // expected-error {{union member 'm6' has a non-trivial destructor}} + struct s7 : Okay { + } m7; +}; + +union U4 { + static int i1; // expected-warning {{static data member 'i1' in union is a C++11 extension}} +}; +int U4::i1 = 10; + +union U5 { + int& i1; // expected-error {{union member 'i1' has reference type 'int &'}} +}; + +template <class A, class B> struct Either { + bool tag; + union { // expected-note 6 {{in instantiation of member class}} + A a; + B b; // expected-error 6 {{non-trivial}} + }; + + Either(const A& a) : tag(true), a(a) {} + Either(const B& b) : tag(false), b(b) {} +}; + +void fred() { + Either<int,Virtual> virt(0); // expected-note {{in instantiation of template}} + Either<int,VirtualBase> vbase(0); // expected-note {{in instantiation of template}} + Either<int,Ctor> ctor(0); // expected-note {{in instantiation of template}} + Either<int,CopyCtor> copyctor(0); // expected-note {{in instantiation of template}} + Either<int,CopyAssign> copyassign(0); // expected-note {{in instantiation of template}} + Either<int,Dtor> dtor(0); // expected-note {{in instantiation of template}} + Either<int,Okay> okay(0); +} diff --git a/clang/test/CXX/class/class.union/p2-0x.cpp b/clang/test/CXX/class/class.union/p2-0x.cpp new file mode 100644 index 0000000..b5c4109 --- /dev/null +++ b/clang/test/CXX/class/class.union/p2-0x.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -verify -std=c++11 %s + +// Unlike in C++98, C++11 allows unions to have static data members. + +union U1 { + static constexpr int k1 = 0; + static const int k2 = k1; + static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}} + static constexpr double k4 = k2; + static const double k5 = k4; // expected-warning {{GNU extension}} expected-note {{use 'constexpr'}} + int n[k1 + 3]; +}; + +constexpr int U1::k1; +constexpr int U1::k2; +int U1::k3; + +const double U1::k4; +const double U1::k5; + +template<typename T> +union U2 { + static const int k1; + static double k2; + T t; +}; +template<typename T> constexpr int U2<T>::k1 = sizeof(U2<T>); +template<typename T> double U2<T>::k2 = 5.3; + +static_assert(U2<int>::k1 == sizeof(int), ""); +static_assert(U2<char>::k1 == sizeof(char), ""); + +union U3 { + static const int k; + U3() : k(0) {} // expected-error {{does not name a non-static data member}} +}; + +struct S { + union { + static const int n; // expected-error {{static members cannot be declared in an anonymous union}} + int a; + int b; + }; +}; +static union { + static const int k; // expected-error {{static members cannot be declared in an anonymous union}} + int n; +}; |