blob: dee6d131e4adbbcc3ef2ba292090ce2bba21527d [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 Gregor06a9f362010-05-01 20:49:11 +00004 // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} \
5 // expected-note {{synthesized method is first required here}}
Anders Carlssond1aa8002010-04-23 02:20:12 +00006 int &ref; // expected-note {{declared here}} \
Douglas Gregor325e5932010-04-15 00:00:53 +00007 // expected-note{{reference member 'ref' will never be initialized}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00008};
9
Douglas Gregor06a9f362010-05-01 20:49:11 +000010class 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}} \
11 // expected-note {{synthesized method is first required here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000012public:
13 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 Gregor06a9f362010-05-01 20:49:11 +000032 x = cx;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000033 x = cx;
34 z1 = z2;
35}
36
37// Test2
38class T {};
39T t1;
40T t2;
41
Mike Stump1eb44332009-09-09 15:08:12 +000042void g() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000043 t1 = t2;
44}
45
46// Test3
47class V {
48public:
49 V();
50 V &operator = (V &b);
51};
52
53class W : V {};
54W w1, w2;
55
Mike Stump1eb44332009-09-09 15:08:12 +000056void h() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000057 w1 = w2;
58}
59
60// Test4
61
62class B1 {
63public:
64 B1();
65 B1 &operator = (B1 b);
66};
67
68class D1 : B1 {};
69D1 d1, d2;
70
Mike Stump1eb44332009-09-09 15:08:12 +000071void i() {
72 d1 = d2;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000073}
74
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000075// Test5
76
Douglas Gregor06a9f362010-05-01 20:49:11 +000077class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}} \
78 // expected-note {{synthesized method is first required here}}
79
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 Gregor06a9f362010-05-01 20:49:11 +000089 e1 = e2;
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000090}
91
Douglas Gregor6cdc1612010-05-04 15:20:55 +000092namespace ProtectedCheck {
93 struct X {
94 protected:
95 X &operator=(const X&); // expected-note{{declared protected here}}
96 };
97
98 struct Y : public X { };
99
100 void f(Y y) { y = y; }
101
102 struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
103 X x;
104 };
105
106 void f(Z z) { z = z; } //
107}
108
109namespace MultiplePaths {
110 struct X0 {
111 X0 &operator=(const X0&);
112 };
113
114 struct X1 : public virtual X0 { };
115
116 struct X2 : X0, X1 { };
117
118 void f(X2 x2) { x2 = x2; }
119}