overloaded-operator.cpp revision a9efadada0430493a4d68b34b2e76580d0fd8f10
1d7d5f0223bd30dfd618762349c6209dd1d5ea3e6Daniel Dunbar// RUN: clang-cc -fsyntax-only -verify %s 2eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorclass X { }; 3eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 4eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas GregorX operator+(X, X); 5eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 6eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorvoid f(X x) { 7eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor x = x + x; 8eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor} 9eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 10eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Y; 11eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Z; 12eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 13eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Y { 14eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor Y(const Z&); 15eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor}; 16eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 17eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Z { 18eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor Z(const Y&); 19eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor}; 20eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 21eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas GregorY operator+(Y, Y); 22eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorbool operator-(Y, Y); // expected-note{{candidate function}} 23eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorbool operator-(Z, Z); // expected-note{{candidate function}} 24eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 25eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorvoid g(Y y, Z z) { 26eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor y = y + z; 27eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor bool b = y - z; // expected-error{{use of overloaded operator '-' is ambiguous; candidates are:}} 28eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor} 29eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 3096176b3575823ea996c6140380dd17d9240c9766Douglas Gregorstruct A { 313307475eb0dd6e5d88be9392ea8247d0b6b812dfDouglas Gregor bool operator==(Z&); // expected-note 2{{candidate function}} 3296176b3575823ea996c6140380dd17d9240c9766Douglas Gregor}; 3396176b3575823ea996c6140380dd17d9240c9766Douglas Gregor 3496176b3575823ea996c6140380dd17d9240c9766Douglas GregorA make_A(); 35eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor 363307475eb0dd6e5d88be9392ea8247d0b6b812dfDouglas Gregorbool operator==(A&, Z&); // expected-note 2{{candidate function}} 3796176b3575823ea996c6140380dd17d9240c9766Douglas Gregor 3896176b3575823ea996c6140380dd17d9240c9766Douglas Gregorvoid h(A a, const A ac, Z z) { 3996176b3575823ea996c6140380dd17d9240c9766Douglas Gregor make_A() == z; 4096176b3575823ea996c6140380dd17d9240c9766Douglas Gregor a == z; // expected-error{{use of overloaded operator '==' is ambiguous; candidates are:}} 4196176b3575823ea996c6140380dd17d9240c9766Douglas Gregor ac == z; // expected-error{{invalid operands to binary expression ('struct A const' and 'struct Z')}} 4296176b3575823ea996c6140380dd17d9240c9766Douglas Gregor} 4396176b3575823ea996c6140380dd17d9240c9766Douglas Gregor 4496176b3575823ea996c6140380dd17d9240c9766Douglas Gregorstruct B { 4596176b3575823ea996c6140380dd17d9240c9766Douglas Gregor bool operator==(const B&) const; 4696176b3575823ea996c6140380dd17d9240c9766Douglas Gregor 4796176b3575823ea996c6140380dd17d9240c9766Douglas Gregor void test(Z z) { 4896176b3575823ea996c6140380dd17d9240c9766Douglas Gregor make_A() == z; 4996176b3575823ea996c6140380dd17d9240c9766Douglas Gregor } 5096176b3575823ea996c6140380dd17d9240c9766Douglas Gregor}; 51447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor 52447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorenum Enum1 { }; 53447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorenum Enum2 { }; 54447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor 55447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorstruct E1 { 56447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor E1(Enum1) { } 57447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor}; 58447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor 59447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorstruct E2 { 60447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor E2(Enum2); 61447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor}; 62447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor 63447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor// C++ [over.match.oper]p3 - enum restriction. 64447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorfloat& operator==(E1, E2); 65447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor 66447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorvoid enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2) { 67447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor float &f1 = (e1 == e2); 68447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor float &f2 = (enum1 == e2); 69447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor float &f3 = (e1 == enum2); 70d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor float &f4 = (enum1 == enum2); // expected-error{{non-const lvalue reference to type 'float' cannot be initialized with a temporary of type 'bool'}} 71447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor} 7274253736184c0717a0649922551bf9d8b6815651Douglas Gregor 73644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl// PR5244 - Argument-dependent lookup would include the two operators below, 74644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl// which would break later assumptions and lead to a crash. 75644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlclass pr5244_foo 76644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{ 77644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl pr5244_foo(int); 78644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl pr5244_foo(char); 79644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl}; 80644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 81644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlbool operator==(const pr5244_foo& s1, const pr5244_foo& s2); 82644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlbool operator==(char c, const pr5244_foo& s); 83644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 84644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlenum pr5244_bar 85644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{ 86644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl pr5244_BAR 87644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl}; 88644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 89644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlclass pr5244_baz 90644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{ 91644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl pr5244_bar quux; 92644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl}; 93644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 94644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlvoid pr5244_barbaz() 95644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{ 96644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl pr5244_baz quuux; 97644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl (void)(pr5244_BAR == quuux.quux); 98644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl} 99644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 100644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl 10174253736184c0717a0649922551bf9d8b6815651Douglas Gregor 10274253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct PostInc { 10374253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostInc operator++(int); 10474253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostInc& operator++(); 10574253736184c0717a0649922551bf9d8b6815651Douglas Gregor}; 10674253736184c0717a0649922551bf9d8b6815651Douglas Gregor 10774253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct PostDec { 10874253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostDec operator--(int); 10974253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostDec& operator--(); 11074253736184c0717a0649922551bf9d8b6815651Douglas Gregor}; 11174253736184c0717a0649922551bf9d8b6815651Douglas Gregor 11274253736184c0717a0649922551bf9d8b6815651Douglas Gregorvoid incdec_test(PostInc pi, PostDec pd) { 11374253736184c0717a0649922551bf9d8b6815651Douglas Gregor const PostInc& pi1 = pi++; 11474253736184c0717a0649922551bf9d8b6815651Douglas Gregor const PostDec& pd1 = pd--; 11574253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostInc &pi2 = ++pi; 11674253736184c0717a0649922551bf9d8b6815651Douglas Gregor PostDec &pd2 = --pd; 11774253736184c0717a0649922551bf9d8b6815651Douglas Gregor} 11874253736184c0717a0649922551bf9d8b6815651Douglas Gregor 11974253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct SmartPtr { 12074253736184c0717a0649922551bf9d8b6815651Douglas Gregor int& operator*(); 1211ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor long& operator*() const volatile; 12274253736184c0717a0649922551bf9d8b6815651Douglas Gregor}; 12374253736184c0717a0649922551bf9d8b6815651Douglas Gregor 1241ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregorvoid test_smartptr(SmartPtr ptr, const SmartPtr cptr, 1251ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor const volatile SmartPtr cvptr) { 12674253736184c0717a0649922551bf9d8b6815651Douglas Gregor int &ir = *ptr; 1271ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor long &lr = *cptr; 1281ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor long &lr2 = *cvptr; 12974253736184c0717a0649922551bf9d8b6815651Douglas Gregor} 130337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 131337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 132337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorstruct ArrayLike { 133337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor int& operator[](int); 134337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor}; 135337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 136337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_arraylike(ArrayLike a) { 137337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor int& ir = a[17]; 138337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor} 139337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 140337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorstruct SmartRef { 141337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor int* operator&(); 142337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor}; 143337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 144337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_smartref(SmartRef r) { 145337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor int* ip = &r; 146337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor} 147337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 148337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorbool& operator,(X, Y); 149337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 150337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_comma(X x, Y y) { 151337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor bool& b1 = (x, y); 152337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor X& xr = (x, x); 153337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor} 154f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor 155f9eb905197e44ed5634205512074993f6f40470dDouglas Gregorstruct Callable { 156f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor int& operator()(int, double = 2.71828); // expected-note{{candidate function}} 157f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor float& operator()(int, double, long, ...); // expected-note{{candidate function}} 158518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor 159518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor double& operator()(float); // expected-note{{candidate function}} 160518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor}; 161518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor 162518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregorstruct Callable2 { 163518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor int& operator()(int i = 0); 164518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor double& operator()(...) const; 165f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor}; 166f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor 167593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregorstruct DerivesCallable : public Callable { 168593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor}; 169593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor 170593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregorvoid test_callable(Callable c, Callable2 c2, const Callable2& c2c, 171593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor DerivesCallable dc) { 172f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor int &ir = c(1); 173f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor float &fr = c(1, 3.14159, 17, 42); 174f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor 175f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor c(); // expected-error{{no matching function for call to object of type 'struct Callable'; candidates are:}} 176518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor 177518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor double &dr = c(1.0f); 178518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor 179518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor int &ir2 = c2(); 180518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor int &ir3 = c2(1); 181518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor double &fr2 = c2c(); 182593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor 183593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor int &ir4 = dc(17); 184593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor double &fr3 = dc(3.14159f); 185f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor} 186106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor 187621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef float FLOAT; 188621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef int& INTREF; 189621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef INTREF Func1(FLOAT, double); 190106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregortypedef float& Func2(int, double); 191106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor 192106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregorstruct ConvertToFunc { 19354e14c4db764c0636160d26c5bbf491637c83a76John McCall operator Func1*(); // expected-note{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}} 194106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor operator Func2&(); // expected-note{{conversion candidate of type 'float &(&)(int, double)'}} 1959ebae31a97f862771dc5f6bd4923dd97131fed71Douglas Gregor void operator()(); 196106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor}; 197106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor 198106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregorvoid test_funcptr_call(ConvertToFunc ctf) { 199106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor int &i1 = ctf(1.0f, 2.0); 200106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor float &f2 = ctf((short int)1, 1.0f); 201106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor ctf((long int)17, 2.0); // expected-error{{error: call to object of type 'struct ConvertToFunc' is ambiguous; candidates are:}} 2029ebae31a97f862771dc5f6bd4923dd97131fed71Douglas Gregor ctf(); 203106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor} 2048ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor 2058ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct HasMember { 2068ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor int m; 2078ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor}; 2088ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor 2098ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct Arrow1 { 2108ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor HasMember* operator->(); 2118ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor}; 2128ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor 2138ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct Arrow2 { 2148ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor Arrow1 operator->(); // expected-note{{candidate function}} 2158ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor}; 2168ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor 2178ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorvoid test_arrow(Arrow1 a1, Arrow2 a2, const Arrow2 a3) { 2188ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor int &i1 = a1->m; 2198ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor int &i2 = a2->m; 220e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl a3->m; // expected-error{{no viable overloaded 'operator->'; candidate is}} 2218ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor} 222e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor 223e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregorstruct CopyConBase { 224e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor}; 225e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor 226e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregorstruct CopyCon : public CopyConBase { 227e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor CopyCon(const CopyConBase &Base); 228e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor 229e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor CopyCon(const CopyConBase *Base) { 230e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor *this = *Base; 231e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor } 232e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor}; 233fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor 234fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace N { 235fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor struct X { }; 236fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor} 237fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor 238fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace M { 239fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor N::X operator+(N::X, N::X); 240fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor} 241fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor 242fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace M { 243fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor void test_X(N::X x) { 244f680a0fe2dcab32b59fe6fdf71145b5313c40950Douglas Gregor (void)(x + x); 245fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor } 246fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor} 2478a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregor 2488a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorstruct AA { bool operator!=(AA&); }; 2498a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorstruct BB : AA {}; 2508a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorbool x(BB y, BB z) { return y != z; } 2514a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian 2524a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian 2534a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanianstruct AX { 2547a8233a69103a6eeb6602bd4a17fb5d9b7bacaadFariborz Jahanian AX& operator ->(); // expected-note {{declared at}} 2554a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian int b; 2564a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian}; 2574a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian 2584a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanianvoid m() { 2594a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian AX a; 2604a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian a->b = 0; // expected-error {{circular pointer delegation detected}} 2614a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian} 262c4e8321deb2bd83f734a09749460050f40ec51d1John McCall 263c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircA { 2647a8233a69103a6eeb6602bd4a17fb5d9b7bacaadFariborz Jahanian struct CircB& operator->(); // expected-note {{declared at}} 265c4e8321deb2bd83f734a09749460050f40ec51d1John McCall int val; 266c4e8321deb2bd83f734a09749460050f40ec51d1John McCall}; 267c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircB { 2687a8233a69103a6eeb6602bd4a17fb5d9b7bacaadFariborz Jahanian struct CircC& operator->(); // expected-note {{declared at}} 269c4e8321deb2bd83f734a09749460050f40ec51d1John McCall}; 270c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircC { 2717a8233a69103a6eeb6602bd4a17fb5d9b7bacaadFariborz Jahanian struct CircA& operator->(); // expected-note {{declared at}} 272c4e8321deb2bd83f734a09749460050f40ec51d1John McCall}; 273c4e8321deb2bd83f734a09749460050f40ec51d1John McCall 274c4e8321deb2bd83f734a09749460050f40ec51d1John McCallvoid circ() { 275c4e8321deb2bd83f734a09749460050f40ec51d1John McCall CircA a; 276c4e8321deb2bd83f734a09749460050f40ec51d1John McCall a->val = 0; // expected-error {{circular pointer delegation detected}} 277c4e8321deb2bd83f734a09749460050f40ec51d1John McCall} 278a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl 279a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl// PR5360: Arrays should lead to built-in candidates for subscript. 280a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redltypedef enum { 281a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl LastReg = 23, 282a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl} Register; 283a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redlclass RegAlloc { 284a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl int getPriority(Register r) { 285a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl return usepri[r]; 286a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl } 287a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl int usepri[LastReg + 1]; 288a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl}; 289a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl 290a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl// PR5546: Don't generate incorrect and ambiguous overloads for multi-level 291a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl// arrays. 292a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redlnamespace pr5546 293a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl{ 294a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl enum { X }; 295a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl extern const char *const sMoveCommands[][2][2]; 296a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl const char* a() { return sMoveCommands[X][0][0]; } 297a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl const char* b() { return (*(sMoveCommands+X))[0][0]; } 298a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl} 299