Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 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   // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
      5   int &ref;  // expected-note {{declared here}} \
      6   // expected-note{{reference member 'ref' will never be initialized}}
      7 };
      8 
      9 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 // expected-note{{assignment operator for 'Base' first required here}}
     11 public:
     12   X();
     13   const int cint;  // expected-note {{declared here}}
     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) {
     31   x = cx; // expected-note{{assignment operator for 'X' first required here}}
     32   x = cx;
     33   z1 = z2;
     34 }
     35 
     36 // Test2
     37 class T {};
     38 T t1;
     39 T t2;
     40 
     41 void g() {
     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 
     55 void h() {
     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 
     70 void i() {
     71   d1 = d2;
     72 }
     73 
     74 // Test5
     75 
     76 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 
     78 public:
     79   const int a; // expected-note{{declared here}}
     80   E1() : a(0) {}
     81 
     82 };
     83 
     84 E1 e1, e2;
     85 
     86 void j() {
     87   e1 = e2; // expected-note{{assignment operator for 'E1' first required here}}
     88 }
     89 
     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 
    104   void f(Z z) { z = z; }  // expected-note{{implicit copy assignment operator}}
    105 
    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 }
    119