blob: d9cb6fc8e56ca85ce1657812d1bb44bf126ed704 [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}} \
4 // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
5 int &ref; // expected-note {{declared at}} \
6 // expected-note{{reference member 'ref' will never be initialized}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +00007};
8
John McCall7c2342d2010-03-10 11:27:22 +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}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000010public:
11 X();
12 const int cint; // expected-note {{declared at}}
13};
14
15struct Y : X {
16 Y();
17 Y& operator=(const Y&);
18 Y& operator=(volatile Y&);
19 Y& operator=(const volatile Y&);
20 Y& operator=(Y&);
21};
22
23class Z : Y {};
24
25Z z1;
26Z z2;
27
28// Test1
29void f(X x, const X cx) {
Anders Carlssonb6cc91b2009-12-09 03:01:51 +000030 x = cx; // expected-note 2 {{synthesized method is first required here}}
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000031 x = cx;
32 z1 = z2;
33}
34
35// Test2
36class T {};
37T t1;
38T t2;
39
Mike Stump1eb44332009-09-09 15:08:12 +000040void g() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000041 t1 = t2;
42}
43
44// Test3
45class V {
46public:
47 V();
48 V &operator = (V &b);
49};
50
51class W : V {};
52W w1, w2;
53
Mike Stump1eb44332009-09-09 15:08:12 +000054void h() {
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000055 w1 = w2;
56}
57
58// Test4
59
60class B1 {
61public:
62 B1();
63 B1 &operator = (B1 b);
64};
65
66class D1 : B1 {};
67D1 d1, d2;
68
Mike Stump1eb44332009-09-09 15:08:12 +000069void i() {
70 d1 = d2;
Fariborz Jahaniana1fbe862009-06-25 22:40:36 +000071}
72
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000073// Test5
74
John McCall7c2342d2010-03-10 11:27:22 +000075class 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 +000076public:
77 const int a; // expected-note{{declared at}}
78 E1() : a(0) {}
79
80};
81
82E1 e1, e2;
83
Mike Stump1eb44332009-09-09 15:08:12 +000084void j() {
Anders Carlsson5e09d4c2009-07-09 17:47:25 +000085 e1 = e2; // expected-note{{synthesized method is first required here}}
86}
87