1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc class Base { // expected-error {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' can't use copy assignment operator}} \ 4*f4a2713aSLionel Sambuc // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} 5*f4a2713aSLionel Sambuc int &ref; // expected-note {{declared here}} \ 6*f4a2713aSLionel Sambuc // expected-note{{reference member 'ref' will never be initialized}} 7*f4a2713aSLionel Sambuc }; 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc class X : Base { // // expected-error {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' can't use copy assignment operator}} \ 10*f4a2713aSLionel Sambuc // expected-note{{assignment operator for 'Base' first required here}} 11*f4a2713aSLionel Sambuc public: 12*f4a2713aSLionel Sambuc X(); 13*f4a2713aSLionel Sambuc const int cint; // expected-note {{declared here}} 14*f4a2713aSLionel Sambuc }; 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc struct Y : X { 17*f4a2713aSLionel Sambuc Y(); 18*f4a2713aSLionel Sambuc Y& operator=(const Y&); 19*f4a2713aSLionel Sambuc Y& operator=(volatile Y&); 20*f4a2713aSLionel Sambuc Y& operator=(const volatile Y&); 21*f4a2713aSLionel Sambuc Y& operator=(Y&); 22*f4a2713aSLionel Sambuc }; 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc class Z : Y {}; 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc Z z1; 27*f4a2713aSLionel Sambuc Z z2; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc // Test1 f(X x,const X cx)30*f4a2713aSLionel Sambucvoid f(X x, const X cx) { 31*f4a2713aSLionel Sambuc x = cx; // expected-note{{assignment operator for 'X' first required here}} 32*f4a2713aSLionel Sambuc x = cx; 33*f4a2713aSLionel Sambuc z1 = z2; 34*f4a2713aSLionel Sambuc } 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc // Test2 37*f4a2713aSLionel Sambuc class T {}; 38*f4a2713aSLionel Sambuc T t1; 39*f4a2713aSLionel Sambuc T t2; 40*f4a2713aSLionel Sambuc g()41*f4a2713aSLionel Sambucvoid g() { 42*f4a2713aSLionel Sambuc t1 = t2; 43*f4a2713aSLionel Sambuc } 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc // Test3 46*f4a2713aSLionel Sambuc class V { 47*f4a2713aSLionel Sambuc public: 48*f4a2713aSLionel Sambuc V(); 49*f4a2713aSLionel Sambuc V &operator = (V &b); 50*f4a2713aSLionel Sambuc }; 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc class W : V {}; 53*f4a2713aSLionel Sambuc W w1, w2; 54*f4a2713aSLionel Sambuc h()55*f4a2713aSLionel Sambucvoid h() { 56*f4a2713aSLionel Sambuc w1 = w2; 57*f4a2713aSLionel Sambuc } 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambuc // Test4 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc class B1 { 62*f4a2713aSLionel Sambuc public: 63*f4a2713aSLionel Sambuc B1(); 64*f4a2713aSLionel Sambuc B1 &operator = (B1 b); 65*f4a2713aSLionel Sambuc }; 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc class D1 : B1 {}; 68*f4a2713aSLionel Sambuc D1 d1, d2; 69*f4a2713aSLionel Sambuc i()70*f4a2713aSLionel Sambucvoid i() { 71*f4a2713aSLionel Sambuc d1 = d2; 72*f4a2713aSLionel Sambuc } 73*f4a2713aSLionel Sambuc 74*f4a2713aSLionel Sambuc // Test5 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc class E1 { // expected-error{{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' can't use copy assignment operator}} 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambuc public: 79*f4a2713aSLionel Sambuc const int a; // expected-note{{declared here}} E1()80*f4a2713aSLionel Sambuc E1() : a(0) {} 81*f4a2713aSLionel Sambuc 82*f4a2713aSLionel Sambuc }; 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc E1 e1, e2; 85*f4a2713aSLionel Sambuc j()86*f4a2713aSLionel Sambucvoid j() { 87*f4a2713aSLionel Sambuc e1 = e2; // expected-note{{assignment operator for 'E1' first required here}} 88*f4a2713aSLionel Sambuc } 89*f4a2713aSLionel Sambuc 90*f4a2713aSLionel Sambuc namespace ProtectedCheck { 91*f4a2713aSLionel Sambuc struct X { 92*f4a2713aSLionel Sambuc protected: 93*f4a2713aSLionel Sambuc X &operator=(const X&); // expected-note{{declared protected here}} 94*f4a2713aSLionel Sambuc }; 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc struct Y : public X { }; 97*f4a2713aSLionel Sambuc f(Y y)98*f4a2713aSLionel Sambuc void f(Y y) { y = y; } 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambuc struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}} 101*f4a2713aSLionel Sambuc X x; 102*f4a2713aSLionel Sambuc }; 103*f4a2713aSLionel Sambuc f(Z z)104*f4a2713aSLionel Sambuc void f(Z z) { z = z; } // expected-note{{implicit copy assignment operator}} 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc } 107*f4a2713aSLionel Sambuc 108*f4a2713aSLionel Sambuc namespace MultiplePaths { 109*f4a2713aSLionel Sambuc struct X0 { 110*f4a2713aSLionel Sambuc X0 &operator=(const X0&); 111*f4a2713aSLionel Sambuc }; 112*f4a2713aSLionel Sambuc 113*f4a2713aSLionel Sambuc struct X1 : public virtual X0 { }; 114*f4a2713aSLionel Sambuc 115*f4a2713aSLionel Sambuc struct X2 : X0, X1 { }; 116*f4a2713aSLionel Sambuc f(X2 x2)117*f4a2713aSLionel Sambuc void f(X2 x2) { x2 = x2; } 118*f4a2713aSLionel Sambuc } 119