default-assignment-operator.cpp revision 1c0c52cb8019f7d0b4ba3e190593e24a5bc60533
1// RUN: clang-cc -fsyntax-only -verify %s 2 3class Base { // expected-error {{cannot define the implicit default assignment operator for 'class Base'}} \ 4 // expected-note {{synthesized method is first required here}} 5 int &ref; // expected-note {{declared at}} 6}; 7 8class X : Base { // // expected-error {{cannot define the implicit default assignment operator for 'class X'}} 9public: 10 X(); 11 const int cint; // expected-note {{declared at}} 12}; 13 14struct Y : X { 15 Y(); 16 Y& operator=(const Y&); 17 Y& operator=(volatile Y&); 18 Y& operator=(const volatile Y&); 19 Y& operator=(Y&); 20}; 21 22class Z : Y {}; 23 24Z z1; 25Z z2; 26 27// Test1 28void f(X x, const X cx) { 29 x = cx; // expected-note {{synthesized method is first required here}} 30 x = cx; 31 z1 = z2; 32} 33 34// Test2 35class T {}; 36T t1; 37T t2; 38 39void g() 40{ 41 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 54void h() 55{ 56 w1 = w2; 57} 58 59// Test4 60 61class B1 { 62public: 63 B1(); 64 B1 &operator = (B1 b); 65}; 66 67class D1 : B1 {}; 68D1 d1, d2; 69 70void i() 71{ 72 d1 = d2; 73} 74 75// Test5 76 77class E1 { // expected-error{{cannot define the implicit default assignment operator for 'class E1', because non-static const member 'a' can't use default assignment operator}} 78public: 79 const int a; // expected-note{{declared at}} 80 E1() : a(0) {} 81 82}; 83 84E1 e1, e2; 85 86void j() 87{ 88 e1 = e2; // expected-note{{synthesized method is first required here}} 89} 90 91