1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5 class Base { // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
6 #if __cplusplus <= 199711L
7 // expected-error@-2 {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}}
8 #endif
9
10 int &ref; // expected-note{{reference member 'ref' will never be initialized}}
11 #if __cplusplus <= 199711L
12 // expected-note@-2 {{declared here}}
13 #else
14 // expected-note@-4 2 {{copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'}}
15 #endif
16 };
17
18 class X : Base {
19 #if __cplusplus <= 199711L
20 // expected-note@-2 {{assignment operator for 'Base' first required here}}
21 // expected-error@-3 {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}}
22 #else
23 // expected-note@-5 2 {{copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator}}
24 #endif
25
26 public:
27 X();
28 const int cint;
29 #if __cplusplus <= 199711L
30 // expected-note@-2 {{declared here}}
31 #endif
32 };
33
34 struct Y : X {
35 Y();
36 Y& operator=(const Y&);
37 Y& operator=(volatile Y&);
38 Y& operator=(const volatile Y&);
39 Y& operator=(Y&);
40 };
41
42 class Z : Y {};
43
44 Z z1;
45 Z z2;
46
47 // Test1
f(X x,const X cx)48 void f(X x, const X cx) {
49 x = cx;
50 #if __cplusplus <= 199711L
51 // expected-note@-2 2{{assignment operator for 'X' first required here}}
52 #else
53 // expected-error@-4 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
54 #endif
55
56 x = cx;
57 #if __cplusplus >= 201103L
58 // expected-error@-2 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
59 #endif
60 z1 = z2;
61 }
62
63 // Test2
64 class T {};
65 T t1;
66 T t2;
67
g()68 void g() {
69 t1 = t2;
70 }
71
72 // Test3
73 class V {
74 public:
75 V();
76 V &operator = (V &b);
77 };
78
79 class W : V {};
80 W w1, w2;
81
h()82 void h() {
83 w1 = w2;
84 }
85
86 // Test4
87
88 class B1 {
89 public:
90 B1();
91 B1 &operator = (B1 b);
92 };
93
94 class D1 : B1 {};
95 D1 d1, d2;
96
i()97 void i() {
98 d1 = d2;
99 }
100
101 // Test5
102
103 class E1 {
104 #if __cplusplus <= 199711L
105 // expected-error@-2 {{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}
106 #endif
107
108 public:
109 const int a;
110 #if __cplusplus <= 199711L
111 // expected-note@-2 {{declared here}}
112 #else
113 // expected-note@-4 {{copy assignment operator of 'E1' is implicitly deleted because field 'a' is of const-qualified type 'const int'}}
114 #endif
E1()115 E1() : a(0) {}
116
117 };
118
119 E1 e1, e2;
120
j()121 void j() {
122 e1 = e2;
123 #if __cplusplus <= 199711L
124 // expected-note@-2 {{assignment operator for 'E1' first required here}}
125 #else
126 // expected-error@-4 {{object of type 'E1' cannot be assigned because its copy assignment operator is implicitly deleted}}
127 #endif
128 }
129
130 namespace ProtectedCheck {
131 struct X {
132 protected:
133 X &operator=(const X&);
134 #if __cplusplus <= 199711L
135 // expected-note@-2 {{declared protected here}}
136 #endif
137 };
138
139 struct Y : public X { };
140
f(Y y)141 void f(Y y) { y = y; }
142
143 struct Z {
144 #if __cplusplus <= 199711L
145 // expected-error@-2 {{'operator=' is a protected member of 'ProtectedCheck::X'}}
146 #endif
147 X x;
148 #if __cplusplus >= 201103L
149 // expected-note@-2 {{copy assignment operator of 'Z' is implicitly deleted because field 'x' has an inaccessible copy assignment operator}}
150 #endif
151 };
152
f(Z z)153 void f(Z z) { z = z; }
154 #if __cplusplus <= 199711L
155 // expected-note@-2 {{implicit copy assignment operator}}
156 #else
157 // expected-error@-4 {{object of type 'ProtectedCheck::Z' cannot be assigned because its copy assignment operator is implicitly deleted}}
158 #endif
159 }
160
161 namespace MultiplePaths {
162 struct X0 {
163 X0 &operator=(const X0&);
164 };
165
166 struct X1 : public virtual X0 { };
167
168 struct X2 : X0, X1 { }; // expected-warning{{direct base 'MultiplePaths::X0' is inaccessible due to ambiguity:\n struct MultiplePaths::X2 -> struct MultiplePaths::X0\n struct MultiplePaths::X2 -> struct MultiplePaths::X1 -> struct MultiplePaths::X0}}
169
f(X2 x2)170 void f(X2 x2) { x2 = x2; }
171 }
172