ambig-user-defined-conversions.cpp revision 58f9e13e87e57236fee4b914eea9be6f92a1c345
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3namespace test0 { 4 struct BASE { 5 operator int &(); // expected-note {{candidate function}} 6 }; 7 struct BASE1 { 8 operator int &(); // expected-note {{candidate function}} 9 }; 10 11 struct B : public BASE, BASE1 {}; 12 13 extern B f(); 14 B b1; 15 16 void func(const int ci, const char cc); // expected-note {{candidate function}} 17 void func(const char ci, const B b); // expected-note {{candidate function}} 18 void func(const B b, const int ci); // expected-note {{candidate function}} 19 20 const int Test1() { 21 22 func(b1, f()); // expected-error {{call to 'func' is ambiguous}} 23 return f(); // expected-error {{conversion from 'test0::B' to 'const int' is ambiguous}} 24 } 25 26 // This used to crash when comparing the two operands. 27 void func2(const char cc); // expected-note {{candidate function}} 28 void func2(const int ci); // expected-note {{candidate function}} 29 void Test2() { 30 func2(b1); // expected-error {{call to 'func2' is ambiguous}} 31 } 32} 33 34namespace test1 { 35 struct E; 36 struct A { 37 A (E&); 38 }; 39 40 struct E { 41 operator A (); 42 }; 43 44 struct C { 45 C (E&); 46 }; 47 48 void f1(A); // expected-note {{candidate function}} 49 void f1(C); // expected-note {{candidate function}} 50 51 void Test2() 52 { 53 E b; 54 f1(b); // expected-error {{call to 'f1' is ambiguous}} 55 // ambiguous because b -> C via constructor and 56 // b → A via constructor or conversion function. 57 } 58} 59 60