blob: 9c969c5b75525650ca5f8cf0ebdcf09735bc9036 [file] [log] [blame]
Douglas Gregor1f2023a2009-07-22 18:25:24 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
Mike Stump3ef84e12009-07-22 20:02:03 +00003void abort() __attribute__((noreturn));
Douglas Gregor1f2023a2009-07-22 18:25:24 +00004
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};
Sebastian Redl38fd4d02009-10-25 22:31:45 +000019class Ctor2 {
20 Ctor2(); // expected-note 3 {{because type 'class Ctor2' has a user-declared constructor}}
21};
Douglas Gregor1f2023a2009-07-22 18:25:24 +000022
23class 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
28class CopyAssign { // expected-note 3 {{because type 'class 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 'class 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}}
Sebastian Redl38fd4d02009-10-25 22:31:45 +000040 Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}}
Douglas Gregor1f2023a2009-07-22 18:25:24 +000041 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 '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 Redl38fd4d02009-10-25 22:31:45 +000058 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 Gregor1f2023a2009-07-22 18:25:24 +000061 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
74union 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 Redl38fd4d02009-10-25 22:31:45 +000081 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 Gregor1f2023a2009-07-22 18:25:24 +000083 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
93template <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.
105void 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 */