blob: 668c60036662b543cf94c40610de4757e3595d6a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00002
Douglas Gregor325e5932010-04-15 00:00:53 +00003class Base { // expected-error {{cannot define the implicit default assignment operator for 'Base', because non-static reference member 'ref' can't use default assignment operator}} \
Douglas Gregor60a8fbb2010-05-05 22:38:15 +00004 // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
Anders Carlssond1aa8002010-04-23 02:20:12 +00005 int &ref; // expected-note {{declared here}} \
Douglas Gregor325e5932010-04-15 00:00:53 +00006 // expected-note{{reference member 'ref' will never be initialized}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00007};
8
Douglas Gregor06a9f362010-05-01 20:49:11 +00009class X : Base { // // expected-error {{cannot define the implicit default assignment operator for 'X', because non-static const member 'cint' can't use default assignment operator}} \
Daniel Dunbar380c2132010-05-11 21:32:35 +000010// expected-note{{assignment operator for 'Base' first required here}}
Douglas Gregor60a8fbb2010-05-05 22:38:15 +000011public:
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000012 X();
Anders Carlssond1aa8002010-04-23 02:20:12 +000013 const int cint; // expected-note {{declared here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000014};
15
16struct Y : X {
17 Y();
18 Y& operator=(const Y&);
19 Y& operator=(volatile Y&);
20 Y& operator=(const volatile Y&);
21 Y& operator=(Y&);
22};
23
24class Z : Y {};
25
26Z z1;
27Z z2;
28
29// Test1
30void f(X x, const X cx) {
Daniel Dunbar380c2132010-05-11 21:32:35 +000031 x = cx; // expected-note{{assignment operator for 'X' first required here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000032 x = cx;
33 z1 = z2;
34}
35
36// Test2
37class T {};
38T t1;
39T t2;
40
Mike Stump1eb44332009-09-09 15:08:12 +000041void g() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000042 t1 = t2;
43}
44
45// Test3
46class V {
47public:
48 V();
49 V &operator = (V &b);
50};
51
52class W : V {};
53W w1, w2;
54
Mike Stump1eb44332009-09-09 15:08:12 +000055void h() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000056 w1 = w2;
57}
58
59// Test4
60
61class B1 {
62public:
63 B1();
64 B1 &operator = (B1 b);
65};
66
67class D1 : B1 {};
68D1 d1, d2;
69
Mike Stump1eb44332009-09-09 15:08:12 +000070void i() {
71 d1 = d2;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000072}
73
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000074// Test5
75
Douglas Gregor60a8fbb2010-05-05 22:38:15 +000076class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}}
Douglas Gregor06a9f362010-05-01 20:49:11 +000077
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000078public:
Anders Carlssond1aa8002010-04-23 02:20:12 +000079 const int a; // expected-note{{declared here}}
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000080 E1() : a(0) {}
81
82};
83
84E1 e1, e2;
85
Mike Stump1eb44332009-09-09 15:08:12 +000086void j() {
Daniel Dunbar380c2132010-05-11 21:32:35 +000087 e1 = e2; // expected-note{{assignment operator for 'E1' first required here}}
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000088}
89
Douglas Gregor6cdc1612010-05-04 15:20:55 +000090namespace ProtectedCheck {
91 struct X {
92 protected:
93 X &operator=(const X&); // expected-note{{declared protected here}}
94 };
95
96 struct Y : public X { };
97
98 void f(Y y) { y = y; }
99
100 struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
101 X x;
102 };
103
Douglas Gregorc63d2c82010-05-12 16:39:35 +0000104 void f(Z z) { z = z; } // expected-note{{implicit default copy assignment operator}}
105
Douglas Gregor6cdc1612010-05-04 15:20:55 +0000106}
107
108namespace MultiplePaths {
109 struct X0 {
110 X0 &operator=(const X0&);
111 };
112
113 struct X1 : public virtual X0 { };
114
115 struct X2 : X0, X1 { };
116
117 void f(X2 x2) { x2 = x2; }
118}