1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorstruct X {
43cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl  int& f(int) const; // expected-note 2 {{candidate function}}
53cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl  float& f(int); // expected-note 2 {{candidate function}}
688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void test_f(int x) const {
888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    int& i = f(x);
988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
1088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
1188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void test_f2(int x) {
1288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    float& f2 = f(x);
1388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
1488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
153cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl  int& g(int) const; // expected-note 2 {{candidate function}}
163cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl  float& g(int); // expected-note 2 {{candidate function}}
173cb069213c8502dbb7a67860d40122d869ed8fd6Sebastian Redl  static double& g(double); // expected-note 2 {{candidate function}}
1888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
1988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void h(int);
203f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor
213f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  void test_member() {
223f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    float& f1 = f(0);
233f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    float& f2 = g(0);
243f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    double& d1 = g(0.0);
253f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  }
263f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor
273f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  void test_member_const() const {
283f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    int &i1 = f(0);
293f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    int &i2 = g(0);
303f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    double& d1 = g(0.0);
313f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  }
323f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor
333f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  static void test_member_static() {
343f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor    double& d1 = g(0.0);
352fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    g(0); // expected-error{{call to 'g' is ambiguous}}
363f20a682baad7f3aa6d2b3a9a3053420e5421e32Douglas Gregor  }
3788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
3888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorvoid test(X x, const X xc, X* xp, const X* xcp, volatile X xv, volatile X* xvp) {
4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  int& i1 = xc.f(0);
4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  int& i2 = xcp->f(0);
4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  float& f1 = x.f(0);
4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  float& f2 = xp->f(0);
442fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  xv.f(0); // expected-error{{no matching member function for call to 'f'}}
452fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  xvp->f(0); // expected-error{{no matching member function for call to 'f'}}
4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
4788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  int& i3 = xc.g(0);
4888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  int& i4 = xcp->g(0);
4988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  float& f3 = x.g(0);
5088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  float& f4 = xp->g(0);
5188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  double& d1 = xp->g(0.0);
5288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  double& d2 = X::g(0.0);
532fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  X::g(0); // expected-error{{call to 'g' is ambiguous}}
5488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
5588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  X::h(0); // expected-error{{call to non-static member function without an object argument}}
5688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor}
57b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor
58b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregorstruct X1 {
59b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor  int& member();
60b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor  float& member() const;
61b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor};
62b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor
63b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregorstruct X2 : X1 { };
64b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor
65b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregorvoid test_X2(X2 *x2p, const X2 *cx2p) {
66b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor  int &ir = x2p->member();
67b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor  float &fr = cx2p->member();
68b1c2ea5dddc9188e2ea30de7f6546f640b85deadDouglas Gregor}
69adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall
70adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall// Tests the exact text used to note the candidates
71adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCallnamespace test1 {
72adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall  class A {
7358f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner    template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
7458f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner    void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
75adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall    void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
76adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall    void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
77adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall    void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
78e81e15ed0c31f828104b339ceb66648d1c815a8bJohn McCall
790c42bb653dc40b1caae010618831e320af824b18Chris Lattner    void bar(double d); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
800c42bb653dc40b1caae010618831e320af824b18Chris Lattner    void bar(int i); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
81651f3eec130099fb46e2ce2c8aee9d01531dc3b5John McCall
820c42bb653dc40b1caae010618831e320af824b18Chris Lattner    void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
830c42bb653dc40b1caae010618831e320af824b18Chris Lattner    void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}}
84f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith
85f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith    // PR 11857
86c608c3c0781e15b74fbbda03f8708cc85a3dd488Richard Smith    void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
87c608c3c0781e15b74fbbda03f8708cc85a3dd488Richard Smith    void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
88c608c3c0781e15b74fbbda03f8708cc85a3dd488Richard Smith    void rab(double n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
89c608c3c0781e15b74fbbda03f8708cc85a3dd488Richard Smith    void rab(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
90f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith    void zab(double n = 0.0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
91f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith    void zab(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
92adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall  };
93adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall
94adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall  void test() {
95adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall    A a;
96adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall    a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}}
97e81e15ed0c31f828104b339ceb66648d1c815a8bJohn McCall
989db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    const A b = A();
99e81e15ed0c31f828104b339ceb66648d1c815a8bJohn McCall    b.bar(0); //expected-error {{no matching member function for call to 'bar'}}
100651f3eec130099fb46e2ce2c8aee9d01531dc3b5John McCall
101651f3eec130099fb46e2ce2c8aee9d01531dc3b5John McCall    a.baz(b); //expected-error {{no matching member function for call to 'baz'}}
102f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith
103f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith    a.rab(); //expected-error {{no matching member function for call to 'rab'}}
104f7b8056f1ff0c0409a9523a34f78b69ab8314becRichard Smith    a.zab(3, 4, 5); //expected-error {{no matching member function for call to 'zab'}}
105adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall  }
106adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall}
107adbb8f8aa44216d30d204e843c4a74abab929daeJohn McCall
10898bfbf5354b8b35fd3efd12932894d7452697226Richard Smithnamespace b7398190 {
10998bfbf5354b8b35fd3efd12932894d7452697226Richard Smith  struct S {
11098bfbf5354b8b35fd3efd12932894d7452697226Richard Smith    int f(); // expected-note {{'this' argument has type 'const b7398190::S', but method is not marked const}}
11198bfbf5354b8b35fd3efd12932894d7452697226Richard Smith    void f(int); // expected-note {{requires 1 argument, but 0 were provided}}
11298bfbf5354b8b35fd3efd12932894d7452697226Richard Smith  };
11398bfbf5354b8b35fd3efd12932894d7452697226Richard Smith  const S *p;
11498bfbf5354b8b35fd3efd12932894d7452697226Richard Smith  int k = p->f(); // expected-error {{no matching member function for call to 'f'}}
11598bfbf5354b8b35fd3efd12932894d7452697226Richard Smith}
116