| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s  | 
 | 2 |  | 
| Mike Stump | 3ef84e1 | 2009-07-22 20:02:03 +0000 | [diff] [blame] | 3 | void abort() __attribute__((noreturn)); | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 4 |  | 
 | 5 | class Okay { | 
 | 6 |   int a_; | 
 | 7 | }; | 
 | 8 |  | 
 | 9 | class Virtual { | 
 | 10 |   virtual void foo() { abort(); } // expected-note 3 {{because type 'class Virtual' has a virtual member function}} | 
 | 11 | }; | 
 | 12 |  | 
 | 13 | class VirtualBase : virtual Okay { // expected-note 3 {{because type 'class VirtualBase' has a virtual base class}} | 
 | 14 | }; | 
 | 15 |  | 
 | 16 | class Ctor { | 
 | 17 |   Ctor() { abort(); } // expected-note 3 {{because type 'class Ctor' has a user-declared constructor}} | 
 | 18 | }; | 
| Sebastian Redl | 38fd4d0 | 2009-10-25 22:31:45 +0000 | [diff] [blame] | 19 | class Ctor2 { | 
 | 20 |   Ctor2(); // expected-note 3 {{because type 'class Ctor2' has a user-declared constructor}} | 
 | 21 | }; | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 22 |  | 
 | 23 | class CopyCtor { | 
 | 24 |   CopyCtor(CopyCtor &cc) { abort(); } // expected-note 3 {{because type 'class CopyCtor' has a user-declared copy constructor}} | 
 | 25 | }; | 
 | 26 |  | 
 | 27 | // FIXME: this should eventually trigger on the operator's declaration line | 
 | 28 | class CopyAssign { // expected-note 3 {{because type 'class CopyAssign' has a user-declared copy assignment operator}} | 
 | 29 |   CopyAssign& operator=(CopyAssign& CA) { abort(); } | 
 | 30 | }; | 
 | 31 |  | 
 | 32 | class Dtor { | 
 | 33 |   ~Dtor() { abort(); } // expected-note 3 {{because type 'class Dtor' has a user-declared destructor}} | 
 | 34 | }; | 
 | 35 |  | 
 | 36 | union U1 { | 
 | 37 |   Virtual v; // expected-error {{union member 'v' has a non-trivial copy constructor}} | 
 | 38 |   VirtualBase vbase; // expected-error {{union member 'vbase' has a non-trivial copy constructor}} | 
 | 39 |   Ctor ctor; // expected-error {{union member 'ctor' has a non-trivial constructor}} | 
| Sebastian Redl | 38fd4d0 | 2009-10-25 22:31:45 +0000 | [diff] [blame] | 40 |   Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}} | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 41 |   CopyCtor copyctor; // expected-error {{union member 'copyctor' has a non-trivial copy constructor}} | 
 | 42 |   CopyAssign copyassign; // expected-error {{union member 'copyassign' has a non-trivial copy assignment operator}} | 
 | 43 |   Dtor dtor; // expected-error {{union member 'dtor' has a non-trivial destructor}} | 
 | 44 |   Okay okay; | 
 | 45 | }; | 
 | 46 |  | 
 | 47 | union U2 { | 
 | 48 |   struct { | 
 | 49 |     Virtual v; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial copy constructor}} | 
 | 50 |   } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}} | 
 | 51 |   struct { | 
 | 52 |     VirtualBase vbase; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial copy constructor}} | 
 | 53 |   } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}} | 
 | 54 |   struct { | 
 | 55 |     Ctor ctor; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial constructor}} | 
 | 56 |   } m3; // expected-error {{union member 'm3' has a non-trivial constructor}} | 
 | 57 |   struct { | 
| Sebastian Redl | 38fd4d0 | 2009-10-25 22:31:45 +0000 | [diff] [blame] | 58 |     Ctor2 ctor2; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial constructor}} | 
 | 59 |   } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}} | 
 | 60 |   struct { | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 61 |     CopyCtor copyctor; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial copy constructor}} | 
 | 62 |   } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} | 
 | 63 |   struct { | 
 | 64 |     CopyAssign copyassign; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial copy assignment operator}} | 
 | 65 |   } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}} | 
 | 66 |   struct { | 
 | 67 |     Dtor dtor; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial destructor}} | 
 | 68 |   } m6; // expected-error {{union member 'm6' has a non-trivial destructor}} | 
 | 69 |   struct { | 
 | 70 |     Okay okay; | 
 | 71 |   } m7; | 
 | 72 | }; | 
 | 73 |  | 
 | 74 | union U3 { | 
 | 75 |   struct s1 : Virtual { // expected-note {{because type 'struct U3::s1' has a base class with a non-trivial copy constructor}} | 
 | 76 |   } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}} | 
 | 77 |   struct s2 : VirtualBase { // expected-note {{because type 'struct U3::s2' has a base class with a non-trivial copy constructor}} | 
 | 78 |   } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}} | 
 | 79 |   struct s3 : Ctor { // expected-note {{because type 'struct U3::s3' has a base class with a non-trivial constructor}} | 
 | 80 |   } m3; // expected-error {{union member 'm3' has a non-trivial constructor}} | 
| Sebastian Redl | 38fd4d0 | 2009-10-25 22:31:45 +0000 | [diff] [blame] | 81 |   struct s3a : Ctor2 { // expected-note {{because type 'struct U3::s3a' has a base class with a non-trivial constructor}} | 
 | 82 |   } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}} | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 83 |   struct s4 : CopyCtor { // expected-note {{because type 'struct U3::s4' has a base class with a non-trivial copy constructor}} | 
 | 84 |   } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} | 
 | 85 |   struct s5 : CopyAssign { // expected-note {{because type 'struct U3::s5' has a base class with a non-trivial copy assignment operator}} | 
 | 86 |   } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}} | 
 | 87 |   struct s6 : Dtor { // expected-note {{because type 'struct U3::s6' has a base class with a non-trivial destructor}} | 
 | 88 |   } m6; // expected-error {{union member 'm6' has a non-trivial destructor}} | 
 | 89 |   struct s7 : Okay { | 
 | 90 |   } m7; | 
 | 91 | }; | 
 | 92 |  | 
 | 93 | template <class A, class B> struct Either { | 
 | 94 |   bool tag; | 
 | 95 |   union { | 
 | 96 |     A a; | 
 | 97 |     B b; | 
 | 98 |   }; | 
 | 99 |  | 
 | 100 |   Either(A& a) : tag(true), a(a) {} | 
 | 101 |   Either(B& b) : tag(false), b(b) {} | 
 | 102 | }; | 
 | 103 |  | 
 | 104 | /* FIXME: this should work, but crashes in template code. | 
 | 105 | void fred() { | 
 | 106 |   Either<int,Virtual> virt(0); | 
 | 107 |   Either<int,VirtualBase> vbase(0); | 
 | 108 |   Either<int,Ctor> ctor(0); | 
 | 109 |   Either<int,CopyCtor> copyctor(0); | 
 | 110 |   Either<int,CopyAssign> copyassign(0); | 
 | 111 |   Either<int,Dtor> dtor(0); | 
 | 112 |   Either<int,Okay> okay(0); | 
 | 113 | } | 
 | 114 |  */ |