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