1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 2a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 36698be8a6930730df5e61c941197e72682196187Richard Smithclass Base { // expected-error {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' can't use copy assignment operator}} \ 460a8fbb4242e2535ccddd1fa2d8257ec1bf749c2Douglas Gregor // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} 5d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson int &ref; // expected-note {{declared here}} \ 6325e593a83b20d9bce3628aa78fda983b554814eDouglas Gregor // expected-note{{reference member 'ref' will never be initialized}} 7a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian}; 8a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 96698be8a6930730df5e61c941197e72682196187Richard Smithclass 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}} \ 10380c2139959d8608782292984b457640a143a70dDaniel Dunbar// expected-note{{assignment operator for 'Base' first required here}} 1160a8fbb4242e2535ccddd1fa2d8257ec1bf749c2Douglas Gregorpublic: 12a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian X(); 13d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson const int cint; // expected-note {{declared here}} 14a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian}; 15a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 16a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianstruct Y : X { 17a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian Y(); 18a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian Y& operator=(const Y&); 19a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian Y& operator=(volatile Y&); 20a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian Y& operator=(const volatile Y&); 21a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian Y& operator=(Y&); 22a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian}; 23a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 24a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass Z : Y {}; 25a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 26a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianZ z1; 27a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianZ z2; 28a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 29a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian// Test1 30a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianvoid f(X x, const X cx) { 31380c2139959d8608782292984b457640a143a70dDaniel Dunbar x = cx; // expected-note{{assignment operator for 'X' first required here}} 32a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian x = cx; 33a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian z1 = z2; 34a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian} 35a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 36a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian// Test2 37a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass T {}; 38a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianT t1; 39a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianT t2; 40a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid g() { 42a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian t1 = t2; 43a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian} 44a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 45a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian// Test3 46a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass V { 47a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianpublic: 48a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian V(); 49a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian V &operator = (V &b); 50a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian}; 51a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 52a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass W : V {}; 53a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianW w1, w2; 54a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid h() { 56a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian w1 = w2; 57a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian} 58a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 59a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian// Test4 60a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 61a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass B1 { 62a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianpublic: 63a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian B1(); 64a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian B1 &operator = (B1 b); 65a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian}; 66a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 67a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanianclass D1 : B1 {}; 68a1fbe8611694835a647811b97e56ec62d504110aFariborz JahanianD1 d1, d2; 69a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid i() { 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump d1 = d2; 72a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian} 73a1fbe8611694835a647811b97e56ec62d504110aFariborz Jahanian 745e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson// Test5 755e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson 766698be8a6930730df5e61c941197e72682196187Richard Smithclass E1 { // expected-error{{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' can't use copy assignment operator}} 7706a9f3680d22529a2fcf20c52d71cf221d99d910Douglas Gregor 785e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlssonpublic: 79d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson const int a; // expected-note{{declared here}} 805e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson E1() : a(0) {} 815e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson 825e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson}; 835e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson 845e09d4c96dc2846cc1fc75f80f5632612247354bAnders CarlssonE1 e1, e2; 855e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid j() { 87380c2139959d8608782292984b457640a143a70dDaniel Dunbar e1 = e2; // expected-note{{assignment operator for 'E1' first required here}} 885e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson} 895e09d4c96dc2846cc1fc75f80f5632612247354bAnders Carlsson 906cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregornamespace ProtectedCheck { 916cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor struct X { 926cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor protected: 936cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor X &operator=(const X&); // expected-note{{declared protected here}} 946cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor }; 956cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 966cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor struct Y : public X { }; 976cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 986cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor void f(Y y) { y = y; } 996cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1006cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}} 1016cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor X x; 1026cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor }; 1036cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1046698be8a6930730df5e61c941197e72682196187Richard Smith void f(Z z) { z = z; } // expected-note{{implicit copy assignment operator}} 105c63d2c8469d6b96712b324f76b4af07e1852313fDouglas Gregor 1066cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor} 1076cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1086cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregornamespace MultiplePaths { 1096cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor struct X0 { 1106cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor X0 &operator=(const X0&); 1116cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor }; 1126cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1136cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor struct X1 : public virtual X0 { }; 1146cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines struct X2 : X0, X1 { }; // expected-warning{{direct base 'MultiplePaths::X0' is inaccessible due to ambiguity:\n struct MultiplePaths::X2 -> struct MultiplePaths::X0\n struct MultiplePaths::X2 -> struct MultiplePaths::X1 -> struct MultiplePaths::X0}} 1166cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor 1176cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor void f(X2 x2) { x2 = x2; } 1186cdc161527a513f28dfc6f6ec27eb287f8268024Douglas Gregor} 119