blob: bf45e5d4d888addbcedcb880864a2d8b5ea75f92 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Fariborz Jahanian455acd92009-09-22 19:53:15 +00002
John McCall9a0e5302010-01-08 18:40:32 +00003namespace test0 {
4 struct BASE {
5 operator int &(); // expected-note {{candidate function}}
6 };
7 struct BASE1 {
8 operator int &(); // expected-note {{candidate function}}
9 };
Fariborz Jahanian455acd92009-09-22 19:53:15 +000010
John McCall9a0e5302010-01-08 18:40:32 +000011 struct B : public BASE, BASE1 {};
Fariborz Jahanian455acd92009-09-22 19:53:15 +000012
John McCall9a0e5302010-01-08 18:40:32 +000013 extern B f();
14 B b1;
Fariborz Jahanian455acd92009-09-22 19:53:15 +000015
John McCall9a0e5302010-01-08 18:40:32 +000016 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}}
Fariborz Jahanian455acd92009-09-22 19:53:15 +000019
Chandler Carruth5495f372010-07-14 06:36:18 +000020 const int Test1() {
Douglas Gregor5291c3c2010-07-13 08:18:22 +000021
John McCall9a0e5302010-01-08 18:40:32 +000022 func(b1, f()); // expected-error {{call to 'func' is ambiguous}}
Chris Lattner58f9e132010-09-05 00:04:01 +000023 return f(); // expected-error {{conversion from 'test0::B' to 'const int' is ambiguous}}
John McCall9a0e5302010-01-08 18:40:32 +000024 }
John McCall1d318332010-01-12 00:44:57 +000025
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 }
Fariborz Jahanian455acd92009-09-22 19:53:15 +000032}
33
John McCall9a0e5302010-01-08 18:40:32 +000034namespace test1 {
35 struct E;
36 struct A {
37 A (E&);
38 };
Fariborz Jahanian99d6c442009-09-28 19:06:58 +000039
John McCall9a0e5302010-01-08 18:40:32 +000040 struct E {
41 operator A ();
42 };
Fariborz Jahanian99d6c442009-09-28 19:06:58 +000043
John McCall9a0e5302010-01-08 18:40:32 +000044 struct C {
45 C (E&);
46 };
Fariborz Jahanian99d6c442009-09-28 19:06:58 +000047
John McCall9a0e5302010-01-08 18:40:32 +000048 void f1(A); // expected-note {{candidate function}}
49 void f1(C); // expected-note {{candidate function}}
Fariborz Jahanian99d6c442009-09-28 19:06:58 +000050
John McCall9a0e5302010-01-08 18:40:32 +000051 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 }
Fariborz Jahanian99d6c442009-09-28 19:06:58 +000058}
59
Douglas Gregorf2ae5262011-01-20 00:18:04 +000060namespace rdar8876150 {
61 struct A { operator bool(); };
62 struct B : A { };
63 struct C : A { };
64 struct D : B, C { };
65
66 bool f(D d) { return !d; } // expected-error{{ambiguous conversion from derived class 'rdar8876150::D' to base class 'rdar8876150::A':}}
67}