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