p1.cpp revision aa1e1928703f6a44d25182cd8f1978acd1dcb7ed
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 4 {{because type 'Virtual' has a virtual member function}}
11};
12
13class VirtualBase : virtual Okay { // expected-note 4 {{because type 'VirtualBase' has a virtual base class}}
14};
15
16class Ctor {
17  Ctor() { abort(); } // expected-note 4 {{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};
22class CtorTmpl {
23  template<typename T> CtorTmpl(); // expected-note {{because type 'CtorTmpl' has a user-declared constructor}}
24};
25
26class CopyCtor {
27  CopyCtor(CopyCtor &cc) { abort(); } // expected-note 4 {{because type 'CopyCtor' has a user-declared copy constructor}}
28};
29
30class CopyAssign {
31  CopyAssign& operator=(CopyAssign& CA) { abort(); } // expected-note 4 {{because type 'CopyAssign' has a user-declared copy assignment operator}}
32};
33
34class Dtor {
35  ~Dtor() { abort(); } // expected-note 4 {{because type 'Dtor' has a user-declared destructor}}
36};
37
38union U1 {
39  Virtual v; // expected-error {{union member 'v' has a non-trivial copy constructor}}
40  VirtualBase vbase; // expected-error {{union member 'vbase' has a non-trivial copy constructor}}
41  Ctor ctor; // expected-error {{union member 'ctor' has a non-trivial constructor}}
42  Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}}
43  CtorTmpl ctortmpl; // expected-error {{union member 'ctortmpl' has a non-trivial constructor}}
44  CopyCtor copyctor; // expected-error {{union member 'copyctor' has a non-trivial copy constructor}}
45  CopyAssign copyassign; // expected-error {{union member 'copyassign' has a non-trivial copy assignment operator}}
46  Dtor dtor; // expected-error {{union member 'dtor' has a non-trivial destructor}}
47  Okay okay;
48};
49
50union U2 {
51  struct {
52    Virtual v; // expected-note {{because type 'U2::<anonymous struct}}
53  } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}}
54  struct {
55    VirtualBase vbase; // expected-note {{because type 'U2::<anonymous struct}}
56  } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
57  struct {
58    Ctor ctor; // expected-note {{because type 'U2::<anonymous struct}}
59  } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
60  struct {
61    Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous struct}}
62  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
63  struct {
64    CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous struct}}
65  } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
66  struct {
67    CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous struct}}
68  } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}}
69  struct {
70    Dtor dtor; // expected-note {{because type 'U2::<anonymous struct}}
71  } m6; // expected-error {{union member 'm6' has a non-trivial destructor}}
72  struct {
73    Okay okay;
74  } m7;
75};
76
77union U3 {
78  struct s1 : Virtual { // expected-note {{because type 'U3::s1' has a base class with a non-trivial copy constructor}}
79  } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}}
80  struct s2 : VirtualBase { // expected-note {{because type 'U3::s2' has a base class with a non-trivial copy constructor}}
81  } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
82  struct s3 : Ctor { // expected-note {{because type 'U3::s3' has a base class with a non-trivial constructor}}
83  } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
84  struct s3a : Ctor2 { // expected-note {{because type 'U3::s3a' has a base class with a non-trivial constructor}}
85  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
86  struct s4 : CopyCtor { // expected-note {{because type 'U3::s4' has a base class with a non-trivial copy constructor}}
87  } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
88  struct s5 : CopyAssign { // expected-note {{because type 'U3::s5' has a base class with a non-trivial copy assignment operator}}
89  } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}}
90  struct s6 : Dtor { // expected-note {{because type 'U3::s6' has a base class with a non-trivial destructor}}
91  } m6; // expected-error {{union member 'm6' has a non-trivial destructor}}
92  struct s7 : Okay {
93  } m7;
94};
95
96union U4 {
97  static int i1; // expected-warning {{static data member 'i1' in union is a C++11 extension}}
98};
99int U4::i1 = 10;
100
101union U5 {
102  int& i1; // expected-error {{union member 'i1' has reference type 'int &'}}
103};
104
105template <class A, class B> struct Either {
106  bool tag;
107  union { // expected-note 6 {{in instantiation of member class}}
108    A a;
109    B b; // expected-error 6 {{non-trivial}}
110  };
111
112  Either(const A& a) : tag(true), a(a) {}
113  Either(const B& b) : tag(false), b(b) {}
114};
115
116void fred() {
117  Either<int,Virtual> virt(0); // expected-note {{in instantiation of template}}
118  Either<int,VirtualBase> vbase(0); // expected-note {{in instantiation of template}}
119  Either<int,Ctor> ctor(0); // expected-note {{in instantiation of template}}
120  Either<int,CopyCtor> copyctor(0); // expected-note {{in instantiation of template}}
121  Either<int,CopyAssign> copyassign(0); // expected-note {{in instantiation of template}}
122  Either<int,Dtor> dtor(0); // expected-note {{in instantiation of template}}
123  Either<int,Okay> okay(0);
124}
125