172 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4 5class Base { // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}6#if __cplusplus <= 199711L7// expected-error@-2 {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}}8#endif9 10 int &ref; // expected-note{{reference member 'ref' will never be initialized}}11#if __cplusplus <= 199711L12 // expected-note@-2 {{declared here}}13#else14 // expected-note@-4 2 {{copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'}}15#endif16};17 18class X : Base {19#if __cplusplus <= 199711L20// expected-note@-2 {{assignment operator for 'Base' first required here}}21// expected-error@-3 {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}}22#else23// expected-note@-5 2 {{copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator}}24#endif25 26public: 27 X();28 const int cint;29#if __cplusplus <= 199711L30// expected-note@-2 {{declared here}}31#endif32}; 33 34struct Y : X { 35 Y();36 Y& operator=(const Y&);37 Y& operator=(volatile Y&);38 Y& operator=(const volatile Y&);39 Y& operator=(Y&);40}; 41 42class Z : Y {};43 44Z z1;45Z z2;46 47// Test148void f(X x, const X cx) {49 x = cx;50#if __cplusplus <= 199711L51 // expected-note@-2 2{{assignment operator for 'X' first required here}}52#else53 // expected-error@-4 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}54#endif55 56 x = cx;57#if __cplusplus >= 201103L58 // expected-error@-2 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}59#endif60 z1 = z2;61}62 63// Test264class T {};65T t1;66T t2;67 68void g() {69 t1 = t2;70}71 72// Test373class V {74public:75 V();76 V &operator = (V &b);77};78 79class W : V {};80W w1, w2;81 82void h() {83 w1 = w2;84}85 86// Test487 88class B1 {89public:90 B1();91 B1 &operator = (B1 b);92};93 94class D1 : B1 {};95D1 d1, d2;96 97void i() {98 d1 = d2;99}100 101// Test5102 103class E1 {104#if __cplusplus <= 199711L105// expected-error@-2 {{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}106#endif107 108public:109 const int a;110#if __cplusplus <= 199711L111// expected-note@-2 {{declared here}}112#else113// expected-note@-4 {{copy assignment operator of 'E1' is implicitly deleted because field 'a' is of const-qualified type 'const int'}}114#endif115 E1() : a(0) {}116 117};118 119E1 e1, e2;120 121void j() {122 e1 = e2;123#if __cplusplus <= 199711L124 // expected-note@-2 {{assignment operator for 'E1' first required here}}125#else126 // expected-error@-4 {{object of type 'E1' cannot be assigned because its copy assignment operator is implicitly deleted}}127#endif128}129 130namespace ProtectedCheck {131 struct X {132 protected:133 X &operator=(const X&);134#if __cplusplus <= 199711L135 // expected-note@-2 {{declared protected here}}136#endif137 };138 139 struct Y : public X { };140 141 void f(Y y) { y = y; }142 143 struct Z {144#if __cplusplus <= 199711L145 // expected-error@-2 {{'operator=' is a protected member of 'ProtectedCheck::X'}}146#endif147 X x;148#if __cplusplus >= 201103L149 // expected-note@-2 {{copy assignment operator of 'Z' is implicitly deleted because field 'x' has an inaccessible copy assignment operator}}150#endif151 };152 153 void f(Z z) { z = z; }154#if __cplusplus <= 199711L155 // expected-note@-2 {{implicit copy assignment operator}}156#else157 // expected-error@-4 {{object of type 'Z' cannot be assigned because its copy assignment operator is implicitly deleted}}158#endif159}160 161namespace MultiplePaths {162 struct X0 { 163 X0 &operator=(const X0&);164 };165 166 struct X1 : public virtual X0 { };167 168 struct X2 : X0, X1 { }; // expected-warning{{direct base 'X0' is inaccessible due to ambiguity:\n struct MultiplePaths::X2 -> X0\n struct MultiplePaths::X2 -> X1 -> X0}}169 170 void f(X2 x2) { x2 = x2; }171}172