blob: 0be5df39b159040f7c2ecb7d0e51e4b5037ffb6c [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}} \
Douglas Gregorbbbe0742010-05-11 20:24:17 +000010// expected-note{{assignment operator for 'Base' first required here}} \
11 // expected-note{{implicit default copy assignment operator}}
Douglas Gregor60a8fbb2010-05-05 22:38:15 +000012public:
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000013 X();
Anders Carlssond1aa8002010-04-23 02:20:12 +000014 const int cint; // expected-note {{declared here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000015};
16
17struct Y : X {
18 Y();
19 Y& operator=(const Y&);
20 Y& operator=(volatile Y&);
21 Y& operator=(const volatile Y&);
22 Y& operator=(Y&);
23};
24
25class Z : Y {};
26
27Z z1;
28Z z2;
29
30// Test1
31void f(X x, const X cx) {
Douglas Gregorbbbe0742010-05-11 20:24:17 +000032 x = cx; // expected-note{{assignment operator for 'X' first required here}} \
33 // expected-note{{implicit default copy assignment operator}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000034 x = cx;
35 z1 = z2;
36}
37
38// Test2
39class T {};
40T t1;
41T t2;
42
Mike Stump1eb44332009-09-09 15:08:12 +000043void g() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000044 t1 = t2;
45}
46
47// Test3
48class V {
49public:
50 V();
51 V &operator = (V &b);
52};
53
54class W : V {};
55W w1, w2;
56
Mike Stump1eb44332009-09-09 15:08:12 +000057void h() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000058 w1 = w2;
59}
60
61// Test4
62
63class B1 {
64public:
65 B1();
66 B1 &operator = (B1 b);
67};
68
69class D1 : B1 {};
70D1 d1, d2;
71
Mike Stump1eb44332009-09-09 15:08:12 +000072void i() {
73 d1 = d2;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000074}
75
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000076// Test5
77
Douglas Gregor60a8fbb2010-05-05 22:38:15 +000078class 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 +000079
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000080public:
Anders Carlssond1aa8002010-04-23 02:20:12 +000081 const int a; // expected-note{{declared here}}
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000082 E1() : a(0) {}
83
84};
85
86E1 e1, e2;
87
Mike Stump1eb44332009-09-09 15:08:12 +000088void j() {
Douglas Gregorbbbe0742010-05-11 20:24:17 +000089 // FIXME: duplicated!
90 e1 = e2; // expected-note{{assignment operator for 'E1' first required here}} \
91 // expected-note{{implicit default copy assignment operator}}
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000092}
93
Douglas Gregor6cdc1612010-05-04 15:20:55 +000094namespace ProtectedCheck {
95 struct X {
96 protected:
97 X &operator=(const X&); // expected-note{{declared protected here}}
98 };
99
100 struct Y : public X { };
101
102 void f(Y y) { y = y; }
103
104 struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
105 X x;
106 };
107
Douglas Gregorbbbe0742010-05-11 20:24:17 +0000108 void f(Z z) { z = z; } // expected-note{{implicit default copy assignment operator}}
109
Douglas Gregor6cdc1612010-05-04 15:20:55 +0000110}
111
112namespace MultiplePaths {
113 struct X0 {
114 X0 &operator=(const X0&);
115 };
116
117 struct X1 : public virtual X0 { };
118
119 struct X2 : X0, X1 { };
120
121 void f(X2 x2) { x2 = x2; }
122}