xref: /llvm-project/clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp (revision 18a0313149ea2d6134e566d9190ecede96e77afb)
1febf5c97SIlya Biryukov // RUN: %clang_cc1 -fsyntax-only -verify %s
2febf5c97SIlya Biryukov // RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s
3febf5c97SIlya Biryukov 
4febf5c97SIlya Biryukov namespace ambig {
5febf5c97SIlya Biryukov   struct Foo {
6febf5c97SIlya Biryukov     operator int();
7febf5c97SIlya Biryukov     operator const char *();
8febf5c97SIlya Biryukov   };
9febf5c97SIlya Biryukov 
10febf5c97SIlya Biryukov 
11febf5c97SIlya Biryukov   void func(const char*, long);
12febf5c97SIlya Biryukov   void func(const char*, const char*);
13febf5c97SIlya Biryukov   void func(int, int);
14febf5c97SIlya Biryukov 
doit(Foo x)15febf5c97SIlya Biryukov   bool doit(Foo x) {
16febf5c97SIlya Biryukov     func(x, x); // expected-error {{call to 'func' is ambiguous}}
17febf5c97SIlya Biryukov                 // expected-note@* 3{{candidate}}
18febf5c97SIlya Biryukov     // Check that two functions with best conversions are at the top.
19febf5c97SIlya Biryukov     // CHECK: error: call to 'func' is ambiguous
20febf5c97SIlya Biryukov     // CHECK-NEXT: func(x, x)
21febf5c97SIlya Biryukov     // CHECK-NEXT: ^~~~
22febf5c97SIlya Biryukov     // CHECK-NEXT: note: candidate function
23febf5c97SIlya Biryukov     // CHECK-NEXT: void func(const char*, const char*)
24febf5c97SIlya Biryukov     // CHECK-NEXT: ^
25febf5c97SIlya Biryukov     // CHECK-NEXT: note: candidate function
26febf5c97SIlya Biryukov     // CHECK-NEXT: void func(int, int)
27febf5c97SIlya Biryukov   }
28febf5c97SIlya Biryukov }
29febf5c97SIlya Biryukov 
30febf5c97SIlya Biryukov namespace bad_conversion {
31febf5c97SIlya Biryukov   struct Foo {
32febf5c97SIlya Biryukov     operator int();
33febf5c97SIlya Biryukov     operator const char *();
34febf5c97SIlya Biryukov   };
35febf5c97SIlya Biryukov 
36febf5c97SIlya Biryukov 
37febf5c97SIlya Biryukov   void func(double*, const char*, long);
38febf5c97SIlya Biryukov   void func(double*, const char*, const char*);
39febf5c97SIlya Biryukov   void func(double*, int, int);
40febf5c97SIlya Biryukov 
doit(Foo x)41febf5c97SIlya Biryukov   bool doit(Foo x) {
42febf5c97SIlya Biryukov     func((int*)0, x, x); // expected-error {{no matching function for call to 'func'}}
43febf5c97SIlya Biryukov                          // expected-note@* 3{{candidate}}
44febf5c97SIlya Biryukov     // Check that two functions with best conversions are at the top.
45febf5c97SIlya Biryukov     // CHECK: error: no matching function for call to 'func'
46febf5c97SIlya Biryukov     // CHECK-NEXT: func((int*)0, x, x)
47febf5c97SIlya Biryukov     // CHECK-NEXT: ^~~~
48febf5c97SIlya Biryukov     // CHECK-NEXT: note: candidate function
49febf5c97SIlya Biryukov     // CHECK-NEXT: void func(double*, const char*, const char*)
50febf5c97SIlya Biryukov     // CHECK-NEXT: ^
51febf5c97SIlya Biryukov     // CHECK-NEXT: note: candidate function
52febf5c97SIlya Biryukov     // CHECK-NEXT: void func(double*, int, int)
53febf5c97SIlya Biryukov   }
54febf5c97SIlya Biryukov }
55*18a03131SIlya Biryukov 
56*18a03131SIlya Biryukov namespace bad_deduction {
57*18a03131SIlya Biryukov   template <class> struct templ {};
58*18a03131SIlya Biryukov   template <class T> void func(templ<T>);
59*18a03131SIlya Biryukov   template <class T> void func(T*);
60*18a03131SIlya Biryukov   template <class T> auto func(T&) -> decltype(T().begin());
61*18a03131SIlya Biryukov   template <class T> auto func(const T&) -> decltype(T().begin());
62*18a03131SIlya Biryukov 
doit()63*18a03131SIlya Biryukov   bool doit() {
64*18a03131SIlya Biryukov     struct record {} r;
65*18a03131SIlya Biryukov     func(r); // expected-error {{no matching function for call to 'func'}}
66*18a03131SIlya Biryukov              // expected-note@* 4{{candidate}}
67*18a03131SIlya Biryukov   }
68*18a03131SIlya Biryukov }
69