p1.cpp revision dfdfc584f2a8d9f1eebd6e6eaa9b1bbff519d8f9
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3void abort() __attribute__((noreturn));
4
5class Okay {
6  int a_;
7};
8
9class Virtual {
10  virtual void foo() { abort(); } // expected-note 3 {{because type 'Virtual' has a virtual member function}}
11};
12
13class VirtualBase : virtual Okay { // expected-note 3 {{because type 'VirtualBase' has a virtual base class}}
14};
15
16class Ctor {
17  Ctor() { abort(); } // expected-note 3 {{because type 'Ctor' has a user-declared constructor}}
18};
19class Ctor2 {
20  Ctor2(); // expected-note 3 {{because type 'Ctor2' has a user-declared constructor}}
21};
22
23class CopyCtor {
24  CopyCtor(CopyCtor &cc) { abort(); } // expected-note 3 {{because type 'CopyCtor' has a user-declared copy constructor}}
25};
26
27// FIXME: this should eventually trigger on the operator's declaration line
28class CopyAssign { // expected-note 3 {{because type 'CopyAssign' has a user-declared copy assignment operator}}
29  CopyAssign& operator=(CopyAssign& CA) { abort(); }
30};
31
32class Dtor {
33  ~Dtor() { abort(); } // expected-note 3 {{because type 'Dtor' has a user-declared destructor}}
34};
35
36union 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}}
40  Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}}
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
47union U2 {
48  struct {
49    Virtual v; // expected-note {{because type 'U2::<anonymous struct}}
50  } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}}
51  struct {
52    VirtualBase vbase; // expected-note {{because type 'U2::<anonymous struct}}
53  } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
54  struct {
55    Ctor ctor; // expected-note {{because type 'U2::<anonymous struct}}
56  } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
57  struct {
58    Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous struct}}
59  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
60  struct {
61    CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous struct}}
62  } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
63  struct {
64    CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous struct}}
65  } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}}
66  struct {
67    Dtor dtor; // expected-note {{because type 'U2::<anonymous struct}}
68  } m6; // expected-error {{union member 'm6' has a non-trivial destructor}}
69  struct {
70    Okay okay;
71  } m7;
72};
73
74union U3 {
75  struct s1 : Virtual { // expected-note {{because type '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 '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 'U3::s3' has a base class with a non-trivial constructor}}
80  } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
81  struct s3a : Ctor2 { // expected-note {{because type 'U3::s3a' has a base class with a non-trivial constructor}}
82  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
83  struct s4 : CopyCtor { // expected-note {{because type '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 '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 '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
93union U4 {
94  static int i1; // expected-error {{static data member 'i1' not allowed in union}}
95};
96
97union U5 {
98  int& i1; // expected-error {{union member 'i1' has reference type 'int &'}}
99};
100
101template <class A, class B> struct Either {
102  bool tag;
103  union {
104    A a;
105    B b;
106  };
107
108  Either(A& a) : tag(true), a(a) {}
109  Either(B& b) : tag(false), b(b) {}
110};
111
112/* FIXME: this should work, but crashes in template code.
113void fred() {
114  Either<int,Virtual> virt(0);
115  Either<int,VirtualBase> vbase(0);
116  Either<int,Ctor> ctor(0);
117  Either<int,CopyCtor> copyctor(0);
118  Either<int,CopyAssign> copyassign(0);
119  Either<int,Dtor> dtor(0);
120  Either<int,Okay> okay(0);
121}
122 */
123