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}} \ |
| 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 Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 7 | }; |
| 8 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +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}} |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 10 | public: |
| 11 | X(); |
| 12 | const int cint; // expected-note {{declared at}} |
| 13 | }; |
| 14 | |
| 15 | struct 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 | |
| 23 | class Z : Y {}; |
| 24 | |
| 25 | Z z1; |
| 26 | Z z2; |
| 27 | |
| 28 | // Test1 |
| 29 | void f(X x, const X cx) { |
Anders Carlsson | b6cc91b | 2009-12-09 03:01:51 +0000 | [diff] [blame] | 30 | x = cx; // expected-note 2 {{synthesized method is first required here}} |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 31 | x = cx; |
| 32 | z1 = z2; |
| 33 | } |
| 34 | |
| 35 | // Test2 |
| 36 | class T {}; |
| 37 | T t1; |
| 38 | T t2; |
| 39 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | void g() { |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 41 | t1 = t2; |
| 42 | } |
| 43 | |
| 44 | // Test3 |
| 45 | class V { |
| 46 | public: |
| 47 | V(); |
| 48 | V &operator = (V &b); |
| 49 | }; |
| 50 | |
| 51 | class W : V {}; |
| 52 | W w1, w2; |
| 53 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | void h() { |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 55 | w1 = w2; |
| 56 | } |
| 57 | |
| 58 | // Test4 |
| 59 | |
| 60 | class B1 { |
| 61 | public: |
| 62 | B1(); |
| 63 | B1 &operator = (B1 b); |
| 64 | }; |
| 65 | |
| 66 | class D1 : B1 {}; |
| 67 | D1 d1, d2; |
| 68 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | void i() { |
| 70 | d1 = d2; |
Fariborz Jahanian | a1fbe86 | 2009-06-25 22:40:36 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 73 | // Test5 |
| 74 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 75 | 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}} |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 76 | public: |
| 77 | const int a; // expected-note{{declared at}} |
| 78 | E1() : a(0) {} |
| 79 | |
| 80 | }; |
| 81 | |
| 82 | E1 e1, e2; |
| 83 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | void j() { |
Anders Carlsson | 5e09d4c | 2009-07-09 17:47:25 +0000 | [diff] [blame] | 85 | e1 = e2; // expected-note{{synthesized method is first required here}} |
| 86 | } |
| 87 | |