Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | 325e593 | 2010-04-15 00:00:53 +0000 | [diff] [blame] | 3 | class 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 Gregor | 60a8fbb | 2010-05-05 22:38:15 +0000 | [diff] [blame] | 4 | // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} |
Anders Carlsson | d1aa800 | 2010-04-23 02:20:12 +0000 | [diff] [blame] | 5 | int &ref; // expected-note {{declared here}} \ |
Douglas Gregor | 325e593 | 2010-04-15 00:00:53 +0000 | [diff] [blame] | 6 | // expected-note{{reference member 'ref' will never be initialized}} |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 7 | }; |
| 8 | |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 9 | class 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}} \ |
Daniel Dunbar | 380c213 | 2010-05-11 21:32:35 +0000 | [diff] [blame] | 10 | // expected-note{{assignment operator for 'Base' first required here}} |
Douglas Gregor | 60a8fbb | 2010-05-05 22:38:15 +0000 | [diff] [blame] | 11 | public: |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 12 | X(); |
Anders Carlsson | d1aa800 | 2010-04-23 02:20:12 +0000 | [diff] [blame] | 13 | const int cint; // expected-note {{declared here}} |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 14 | }; |
| 15 | |
| 16 | struct Y : X { |
| 17 | Y(); |
| 18 | Y& operator=(const Y&); |
| 19 | Y& operator=(volatile Y&); |
| 20 | Y& operator=(const volatile Y&); |
| 21 | Y& operator=(Y&); |
| 22 | }; |
| 23 | |
| 24 | class Z : Y {}; |
| 25 | |
| 26 | Z z1; |
| 27 | Z z2; |
| 28 | |
| 29 | // Test1 |
| 30 | void f(X x, const X cx) { |
Daniel Dunbar | 380c213 | 2010-05-11 21:32:35 +0000 | [diff] [blame] | 31 | x = cx; // expected-note{{assignment operator for 'X' first required here}} |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 32 | x = cx; |
| 33 | z1 = z2; |
| 34 | } |
| 35 | |
| 36 | // Test2 |
| 37 | class T {}; |
| 38 | T t1; |
| 39 | T t2; |
| 40 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | void g() { |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 42 | t1 = t2; |
| 43 | } |
| 44 | |
| 45 | // Test3 |
| 46 | class V { |
| 47 | public: |
| 48 | V(); |
| 49 | V &operator = (V &b); |
| 50 | }; |
| 51 | |
| 52 | class W : V {}; |
| 53 | W w1, w2; |
| 54 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | void h() { |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 56 | w1 = w2; |
| 57 | } |
| 58 | |
| 59 | // Test4 |
| 60 | |
| 61 | class B1 { |
| 62 | public: |
| 63 | B1(); |
| 64 | B1 &operator = (B1 b); |
| 65 | }; |
| 66 | |
| 67 | class D1 : B1 {}; |
| 68 | D1 d1, d2; |
| 69 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | void i() { |
| 71 | d1 = d2; |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 74 | // Test5 |
| 75 | |
Douglas Gregor | 60a8fbb | 2010-05-05 22:38:15 +0000 | [diff] [blame] | 76 | class 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 Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 77 | |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 78 | public: |
Anders Carlsson | d1aa800 | 2010-04-23 02:20:12 +0000 | [diff] [blame] | 79 | const int a; // expected-note{{declared here}} |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 80 | E1() : a(0) {} |
| 81 | |
| 82 | }; |
| 83 | |
| 84 | E1 e1, e2; |
| 85 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | void j() { |
Daniel Dunbar | 380c213 | 2010-05-11 21:32:35 +0000 | [diff] [blame] | 87 | e1 = e2; // expected-note{{assignment operator for 'E1' first required here}} |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Douglas Gregor | 6cdc161 | 2010-05-04 15:20:55 +0000 | [diff] [blame] | 90 | namespace ProtectedCheck { |
| 91 | struct X { |
| 92 | protected: |
| 93 | X &operator=(const X&); // expected-note{{declared protected here}} |
| 94 | }; |
| 95 | |
| 96 | struct Y : public X { }; |
| 97 | |
| 98 | void f(Y y) { y = y; } |
| 99 | |
| 100 | struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}} |
| 101 | X x; |
| 102 | }; |
| 103 | |
Douglas Gregor | c63d2c8 | 2010-05-12 16:39:35 +0000 | [diff] [blame] | 104 | void f(Z z) { z = z; } // expected-note{{implicit default copy assignment operator}} |
| 105 | |
Douglas Gregor | 6cdc161 | 2010-05-04 15:20:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | namespace MultiplePaths { |
| 109 | struct X0 { |
| 110 | X0 &operator=(const X0&); |
| 111 | }; |
| 112 | |
| 113 | struct X1 : public virtual X0 { }; |
| 114 | |
| 115 | struct X2 : X0, X1 { }; |
| 116 | |
| 117 | void f(X2 x2) { x2 = x2; } |
| 118 | } |