blob: baae03cf13479ebdd0572390cb4daa1946198199 [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
John McCall7c2342d2010-03-10 11:27:22 +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}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00004 int &ref; // expected-note {{declared at}}
5};
6
John McCall7c2342d2010-03-10 11:27:22 +00007class 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}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00008public:
9 X();
10 const int cint; // expected-note {{declared at}}
11};
12
13struct Y : X {
14 Y();
15 Y& operator=(const Y&);
16 Y& operator=(volatile Y&);
17 Y& operator=(const volatile Y&);
18 Y& operator=(Y&);
19};
20
21class Z : Y {};
22
23Z z1;
24Z z2;
25
26// Test1
27void f(X x, const X cx) {
Anders Carlssonb6cc91b2009-12-09 03:01:51 +000028 x = cx; // expected-note 2 {{synthesized method is first required here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000029 x = cx;
30 z1 = z2;
31}
32
33// Test2
34class T {};
35T t1;
36T t2;
37
Mike Stump1eb44332009-09-09 15:08:12 +000038void g() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000039 t1 = t2;
40}
41
42// Test3
43class V {
44public:
45 V();
46 V &operator = (V &b);
47};
48
49class W : V {};
50W w1, w2;
51
Mike Stump1eb44332009-09-09 15:08:12 +000052void h() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000053 w1 = w2;
54}
55
56// Test4
57
58class B1 {
59public:
60 B1();
61 B1 &operator = (B1 b);
62};
63
64class D1 : B1 {};
65D1 d1, d2;
66
Mike Stump1eb44332009-09-09 15:08:12 +000067void i() {
68 d1 = d2;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000069}
70
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000071// Test5
72
John McCall7c2342d2010-03-10 11:27:22 +000073class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}}
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000074public:
75 const int a; // expected-note{{declared at}}
76 E1() : a(0) {}
77
78};
79
80E1 e1, e2;
81
Mike Stump1eb44332009-09-09 15:08:12 +000082void j() {
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000083 e1 = e2; // expected-note{{synthesized method is first required here}}
84}
85