1a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -Wbind-to-temporary-copy -verify %s 22f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorclass X { 32f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorpublic: 42f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator bool(); 52f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator int() const; 62def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 72def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor bool f() { 82def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor return operator bool(); 92def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor } 102def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 112def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor float g() { 12578b69b186d9cba0a6ae1dd7f4c04cd6a49f0aacJohn McCall return operator float(); // expected-error{{use of undeclared 'operator float'}} 132def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor } 144cde94a04694d5d24dc9e3bf6c5fa3403629838eEli Friedman 154cde94a04694d5d24dc9e3bf6c5fa3403629838eEli Friedman static operator short(); // expected-error{{conversion function must be a non-static member function}} 162f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor}; 172f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 182f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregoroperator int(); // expected-error{{conversion function must be a non-static member function}} 192f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 2010bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregoroperator int; // expected-error{{'operator int' cannot be the name of a variable or data member}} 2110bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 222f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregortypedef int func_type(int); 232f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregortypedef int array_type[10]; 242f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 252f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorclass Y { 262f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorpublic: 272f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor void operator bool(int, ...) const; // expected-error{{conversion function cannot have a return type}} \ 286e4750188e836e119f8605cbd34023d0a3b18011Chris Lattner // expected-error{{conversion function cannot have any parameters}} 296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines operator bool(int a = 4, int b = 6) const; // expected-error{{conversion function cannot have any parameters}} 316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 326e4750188e836e119f8605cbd34023d0a3b18011Chris Lattner 336e4750188e836e119f8605cbd34023d0a3b18011Chris Lattner operator float(...) const; // expected-error{{conversion function cannot be variadic}} 346e4750188e836e119f8605cbd34023d0a3b18011Chris Lattner 356e4750188e836e119f8605cbd34023d0a3b18011Chris Lattner 362f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator func_type(); // expected-error{{conversion function cannot convert to a function type}} 372f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator array_type(); // expected-error{{conversion function cannot convert to an array type}} 382f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor}; 392f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 402f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 412f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregortypedef int INT; 422f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregortypedef INT* INT_PTR; 432f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 442f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorclass Z { 455f4a6829dc58cab2f76e2b98492859aa3b91e3f2Chris Lattner operator int(); // expected-note {{previous declaration is here}} 465f4a6829dc58cab2f76e2b98492859aa3b91e3f2Chris Lattner operator int**(); // expected-note {{previous declaration is here}} 472f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 482f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator INT(); // expected-error{{conversion function cannot be redeclared}} 492f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}} 502f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor}; 512f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 522f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 532f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorclass A { }; 542f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 552f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorclass B : public A { 562f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregorpublic: 577c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall operator A&() const; // expected-warning{{conversion function converting 'B' to its base class 'A' will never be used}} 5858f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner operator const void() const; // expected-warning{{conversion function converting 'B' to 'const void' will never be used}} 597c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall operator const B(); // expected-warning{{conversion function converting 'B' to itself will never be used}} 602f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor}; 613201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redl 623201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redl// This used to crash Clang. 633201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redlstruct Flip; 64d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregorstruct Flop { 653201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redl Flop(); 66b1622a1fd7b7f4ab8d00d0183d17c90ad25c14e3John McCall Flop(const Flip&); // expected-note{{candidate constructor}} 673201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redl}; 683201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redlstruct Flip { 697abfbdbc97ad8e7f340789f751df1e32b10118b4Douglas Gregor operator Flop() const; // expected-note{{candidate function}} 703201f6beec688ab9fe8750527e28f52d5420e22dSebastian Redl}; 717c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallFlop flop = Flip(); // expected-error {{conversion from 'Flip' to 'Flop' is ambiguous}} 722c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson 732c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson// This tests that we don't add the second conversion declaration to the list of user conversions 742c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlssonstruct C { 752c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson operator const char *() const; 762c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson}; 772c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson 782c59d3c19715cb318a0a5939c735b8345d14d281Anders CarlssonC::operator const char*() const { return 0; } 792c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson 802c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlssonvoid f(const C& c) { 812c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson const char* v = c; 822c59d3c19715cb318a0a5939c735b8345d14d281Anders Carlsson} 83b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian 84b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian// Test. Conversion in base class is visible in derived class. 85b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanianclass XB { 86b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanianpublic: 8778cf9a26d27349a7b9ae83a0b7d5451571b9b41eFariborz Jahanian operator int(); // expected-note {{candidate function}} 88b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian}; 89b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian 90b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanianclass Yb : public XB { 91b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanianpublic: 9278cf9a26d27349a7b9ae83a0b7d5451571b9b41eFariborz Jahanian operator char(); // expected-note {{candidate function}} 93b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian}; 94b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian 95b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanianvoid f(Yb& a) { 967c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall if (a) { } // expected-error {{conversion from 'Yb' to 'bool' is ambiguous}} 97b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian int i = a; // OK. calls XB::operator int(); 98b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian char ch = a; // OK. calls Yb::operator char(); 99b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian} 100b191e2dda9f4dc033cb21f9625a78fe80d4ac105Fariborz Jahanian 10179b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor// Test conversion + copy construction. 10279b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregorclass AutoPtrRef { }; 10379b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 10479b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregorclass AutoPtr { 105b92caa5aa6f428ab1bf1a71bea5a35e15c309d8cJohn McCall AutoPtr(AutoPtr &); // expected-note{{declared private here}} 10679b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 10779b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregorpublic: 10879b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor AutoPtr(); 10979b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor AutoPtr(AutoPtrRef); 11079b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 11179b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor operator AutoPtrRef(); 11279b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor}; 11379b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 11479b680ea869983d62b84a9175eeb6b6efb376326Douglas GregorAutoPtr make_auto_ptr(); 11579b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 11679b680ea869983d62b84a9175eeb6b6efb376326Douglas GregorAutoPtr test_auto_ptr(bool Cond) { 11779b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor AutoPtr p1( make_auto_ptr() ); 11879b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 11979b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor AutoPtr p; 12079b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor if (Cond) 121b92caa5aa6f428ab1bf1a71bea5a35e15c309d8cJohn McCall return p; // expected-error{{calling a private constructor}} 12279b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 12379b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor return AutoPtr(); 12479b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor} 12579b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 12618ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregorstruct A1 { 12718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor A1(const char *); 12818ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor ~A1(); 12979b680ea869983d62b84a9175eeb6b6efb376326Douglas Gregor 13018ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregorprivate: 131b92caa5aa6f428ab1bf1a71bea5a35e15c309d8cJohn McCall A1(const A1&); // expected-note 2 {{declared private here}} 13218ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor}; 13318ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor 13418ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas GregorA1 f() { 135b92caa5aa6f428ab1bf1a71bea5a35e15c309d8cJohn McCall // FIXME: redundant diagnostics! 136b92caa5aa6f428ab1bf1a71bea5a35e15c309d8cJohn McCall return "Hello"; // expected-error {{calling a private constructor}} expected-warning {{an accessible copy constructor}} 13718ef5e28a9a2677f8b1dce1fb2638d66e0a1621fDouglas Gregor} 13805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 13905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregornamespace source_locations { 14005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor template<typename T> 14105baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor struct sneaky_int { 14205baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor typedef int type; 14305baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor }; 14405baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 14505baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor template<typename T, typename U> 14605baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor struct A { }; 14705baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 14805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor template<typename T> 14905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor struct A<T, T> : A<T, int> { }; 15005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 15105baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor struct E { 15205baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor template<typename T> 15305baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor operator A<T, typename sneaky_int<T>::type>&() const; // expected-note{{candidate function}} 15405baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor }; 15505baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 15605baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor void f() { 15705baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor A<float, float> &af = E(); // expected-error{{no viable conversion}} 15805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor A<float, int> &af2 = E(); 15905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor const A<float, int> &caf2 = E(); 16005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor } 16105baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 16205baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor // Check 16305baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor template<typename T> 16405baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor struct E2 { 16505baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor operator T 16605baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor * // expected-error{{pointer to a reference}} 16705baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor () const; 16805baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor }; 16905baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor 17005baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor E2<int&> e2i; // expected-note{{in instantiation}} 17105baacbfd67017b2724f3e0503fd23609f5d32bcDouglas Gregor} 172a3f8137d9f7cd1af7a6cbe736b9419f7eb99e86cJohn McCall 173a3f8137d9f7cd1af7a6cbe736b9419f7eb99e86cJohn McCallnamespace crazy_declarators { 174a3f8137d9f7cd1af7a6cbe736b9419f7eb99e86cJohn McCall struct A { 1750e2c34f92f00628d48968dfea096d36381f494cbStephen Hines (&operator bool())(); // expected-error {{use a typedef to declare a conversion to 'bool (&)()'}} 1760e2c34f92f00628d48968dfea096d36381f494cbStephen Hines *operator int(); // expected-error {{put the complete type after 'operator'}} 1770e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // No suggestion of using a typedef here; that's not possible. 1780e2c34f92f00628d48968dfea096d36381f494cbStephen Hines template<typename T> (&operator T())(); // expected-error-re {{cannot specify any part of a return type in the declaration of a conversion function{{$}}}} 179a3f8137d9f7cd1af7a6cbe736b9419f7eb99e86cJohn McCall }; 180a3f8137d9f7cd1af7a6cbe736b9419f7eb99e86cJohn McCall} 1813fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1823fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregornamespace smart_ptr { 1833fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor class Y { 1843fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor class YRef { }; 1853fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1863fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor Y(Y&); 1873fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1883fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor public: 1893fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor Y(); 1903fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor Y(YRef); 1913fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1923fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor operator YRef(); // expected-note{{candidate function}} 1933fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor }; 1943fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1953fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor struct X { // expected-note{{candidate constructor (the implicit copy constructor) not}} 1963fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor explicit X(Y); 1973fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor }; 1983fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 1993fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor Y make_Y(); 2003fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor 2013fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor X f() { 2023fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor X x = make_Y(); // expected-error{{no viable conversion from 'smart_ptr::Y' to 'smart_ptr::X'}} 2033fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor X x2(make_Y()); 2043fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor return X(Y()); 2053fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor } 2063fbaf3e5d524bfff219d1e3e9ac4801a8411590fDouglas Gregor} 207d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor 208d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregorstruct Any { 209d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor Any(...); 210d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor}; 211d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor 212d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregorstruct Other { 213d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor Other(const Other &); 214d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor Other(); 215d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor}; 216d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor 217d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregorvoid test_any() { 218d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor Any any = Other(); // expected-error{{cannot pass object of non-POD type 'Other' through variadic constructor; call will abort at runtime}} 219d1a272204cef9304df3930d94f66713b05db27d6Douglas Gregor} 220604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 221604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregornamespace PR7055 { 222604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor // Make sure that we don't allow too many conversions in an 223604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor // auto_ptr-like template. In particular, we can't create multiple 224604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor // temporary objects when binding to a reference. 225604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor struct auto_ptr { 226604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor struct auto_ptr_ref { }; 227604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 228604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor auto_ptr(auto_ptr&); 229604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor auto_ptr(auto_ptr_ref); 230604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor explicit auto_ptr(int *); 231604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 232604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor operator auto_ptr_ref(); 233604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor }; 234604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 235604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor struct X { 236604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor X(auto_ptr); 237604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor }; 238604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 239604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor X f() { 240604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor X x(auto_ptr(new int)); 241604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor return X(auto_ptr(new int)); 242604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor } 243604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 244604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor auto_ptr foo(); 245604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 246604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor X e(foo()); 247604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 248604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor struct Y { 249604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor Y(X); 250604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor }; 251604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor 252604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor Y f2(foo()); 253604eb65686590f73551d4ea608b174d2244cdd0fDouglas Gregor} 2544e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2554e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregornamespace PR7934 { 2564e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor typedef unsigned char uint8; 2574e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2584e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor struct MutablePtr { 2594e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor MutablePtr() : ptr(0) {} 2604e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor void *ptr; 2614e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2624e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor operator void*() { return ptr; } 2634e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2644e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor private: 2654e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor operator uint8*() { return reinterpret_cast<uint8*>(ptr); } 2664e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor operator const char*() const { return reinterpret_cast<const char*>(ptr); } 2674e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor }; 2684e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2694e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor void fake_memcpy(const void *); 2704e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor 2714e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor void use() { 2724e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor MutablePtr ptr; 2734e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor fake_memcpy(ptr); 2744e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor } 2754e938f57bdd68b3716a4476acf151cdd27bb8a50Douglas Gregor} 276c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 277c774b2f66478008196f497a227d5ab88ea157582Douglas Gregornamespace rdar8018274 { 278c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct X { }; 279c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct Y { 280c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor operator const struct X *() const; 281c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor }; 282c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 283c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct Z : Y { 284c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor operator struct X * (); 285c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor }; 286c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 287c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor void test() { 288c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor Z x; 289c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor (void) (x != __null); 290c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor } 291c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 292c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 293c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct Base { 294c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor operator int(); 295c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor }; 296c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 297c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct Derived1 : Base { }; 298c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 299c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct Derived2 : Base { }; 300c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 301c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct SuperDerived : Derived1, Derived2 { 302c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor using Derived1::operator int; 303c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor }; 304c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 305c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor struct UeberDerived : SuperDerived { 306c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor operator long(); 307c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor }; 308c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor 309c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor void test2(UeberDerived ud) { 310c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor int i = ud; // expected-error{{ambiguous conversion from derived class 'rdar8018274::SuperDerived' to base class 'rdar8018274::Base'}} 311c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor } 31206ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor 31306ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor struct Base2 { 31406ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor operator int(); 31506ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor }; 31606ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor 31706ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor struct Base3 { 31806ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor operator int(); 31906ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor }; 32006ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor 32106ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor struct Derived23 : Base2, Base3 { 32206ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor using Base2::operator int; 32306ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor }; 32406ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor 32506ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor struct ExtraDerived23 : Derived23 { }; 32606ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor 32706ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor void test3(ExtraDerived23 ed) { 32806ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor int i = ed; 32906ebc98ff017fadfaed515bc06f50ce94ca468d6Douglas Gregor } 330c774b2f66478008196f497a227d5ab88ea157582Douglas Gregor} 331da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor 332da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregornamespace PR8065 { 333da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor template <typename T> struct Iterator; 334da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor template <typename T> struct Container; 335da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor 336da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor template<> 337da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor struct Iterator<int> { 338da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor typedef Container<int> container_type; 339da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor }; 340da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor 341da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor template <typename T> 342da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor struct Container { 343da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor typedef typename Iterator<T>::container_type X; 344da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor operator X(void) { return X(); } 345da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor }; 346da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor 347da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor Container<int> test; 348da0fd9a7faa8b8a666e3c31ff0b5897e0f73f892Douglas Gregor} 3498fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor 3508fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregornamespace PR8034 { 3518fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor struct C { 3528fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor operator int(); 3538fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor 3548fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor private: 3558fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor template <typename T> operator T(); 3568fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor }; 3578fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor int x = C().operator int(); 3588fcc516a5d5b2fec0023a9dced29285a38b95355Douglas Gregor} 3595453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor 3605453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregornamespace PR9336 { 3615453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor template<class T> 3625453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor struct generic_list 3635453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor { 3645453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor template<class Container> 3655453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor operator Container() 3665453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor { 3675453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor Container ar; 3685453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor T* i; 3695453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor ar[0]=*i; 3705453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor return ar; 3715453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor } 3725453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor }; 3735453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor 3745453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor template<class T> 3755453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor struct array 3765453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor { 3775453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor T& operator[](int); 3785453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor const T& operator[](int)const; 3795453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor }; 3805453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor 3815453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor generic_list<generic_list<int> > l; 3825453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor array<array<int> > a = l; 3835453d93ab8668f2d9d0bc02182695b02d207e32dDouglas Gregor} 38487c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith 38587c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smithnamespace PR8800 { 38687c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith struct A; 38787c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith struct C { 38887c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith operator A&(); 38987c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith }; 39087c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith void f() { 39187c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith C c; 39287c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith A& a1(c); 39387c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith A& a2 = c; 39487c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith A& a3 = static_cast<A&>(c); 39587c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith A& a4 = (A&)c; 39687c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith } 39787c1f1f7c400deb2eb40d4599a40006072fb948cRichard Smith} 398f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith 399f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smithnamespace PR12712 { 400f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith struct A {}; 401f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith struct B { 402f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith operator A(); 403f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith operator A() const; 404f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith }; 405f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith struct C : B {}; 406f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith 407f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith A f(const C c) { return c; } 408f108c63ccc576fe6a3ca08399dbcec574b089ea8Richard Smith} 409651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 410651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace PR18234 { 411651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines struct A { 412651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines operator enum E { e } (); // expected-error {{'PR18234::A::E' cannot be defined in a type specifier}} 413651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines operator struct S { int n; } (); // expected-error {{'PR18234::A::S' cannot be defined in a type specifier}} 414651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } a; 415651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines A::S s = a; 416651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines A::E e = a; // expected-note {{here}} 417651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool k1 = e == A::e; // expected-error {{no member named 'e'}} 418651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool k2 = e.n == 0; 419651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 420