Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 2 | |
| 3 | struct X { |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 4 | int& f(int) const; // expected-note 2 {{candidate function}} |
| 5 | float& f(int); // expected-note 2 {{candidate function}} |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 6 | |
| 7 | void test_f(int x) const { |
| 8 | int& i = f(x); |
| 9 | } |
| 10 | |
| 11 | void test_f2(int x) { |
| 12 | float& f2 = f(x); |
| 13 | } |
| 14 | |
Sebastian Redl | 3cb0692 | 2009-02-07 19:52:04 +0000 | [diff] [blame] | 15 | int& g(int) const; // expected-note 2 {{candidate function}} |
| 16 | float& g(int); // expected-note 2 {{candidate function}} |
| 17 | static double& g(double); // expected-note 2 {{candidate function}} |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 18 | |
| 19 | void h(int); |
Douglas Gregor | 3f20a68 | 2009-01-12 23:20:38 +0000 | [diff] [blame] | 20 | |
| 21 | void test_member() { |
| 22 | float& f1 = f(0); |
| 23 | float& f2 = g(0); |
| 24 | double& d1 = g(0.0); |
| 25 | } |
| 26 | |
| 27 | void test_member_const() const { |
| 28 | int &i1 = f(0); |
| 29 | int &i2 = g(0); |
| 30 | double& d1 = g(0.0); |
| 31 | } |
| 32 | |
| 33 | static void test_member_static() { |
| 34 | double& d1 = g(0.0); |
| 35 | g(0); // expected-error{{call to 'g' is ambiguous; candidates are:}} |
| 36 | } |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | void test(X x, const X xc, X* xp, const X* xcp, volatile X xv, volatile X* xvp) { |
| 40 | int& i1 = xc.f(0); |
| 41 | int& i2 = xcp->f(0); |
| 42 | float& f1 = x.f(0); |
| 43 | float& f2 = xp->f(0); |
| 44 | xv.f(0); // expected-error{{no matching member function for call to 'f'; candidates are:}} |
| 45 | xvp->f(0); // expected-error{{no matching member function for call to 'f'; candidates are:}} |
| 46 | |
| 47 | int& i3 = xc.g(0); |
| 48 | int& i4 = xcp->g(0); |
| 49 | float& f3 = x.g(0); |
| 50 | float& f4 = xp->g(0); |
| 51 | double& d1 = xp->g(0.0); |
| 52 | double& d2 = X::g(0.0); |
| 53 | X::g(0); // expected-error{{call to 'g' is ambiguous; candidates are:}} |
| 54 | |
| 55 | X::h(0); // expected-error{{call to non-static member function without an object argument}} |
| 56 | } |
Douglas Gregor | b1c2ea5 | 2009-11-05 00:07:36 +0000 | [diff] [blame] | 57 | |
| 58 | struct X1 { |
| 59 | int& member(); |
| 60 | float& member() const; |
| 61 | }; |
| 62 | |
| 63 | struct X2 : X1 { }; |
| 64 | |
| 65 | void test_X2(X2 *x2p, const X2 *cx2p) { |
| 66 | int &ir = x2p->member(); |
| 67 | float &fr = cx2p->member(); |
| 68 | } |
John McCall | adbb8f8 | 2010-01-13 09:16:55 +0000 | [diff] [blame] | 69 | |
| 70 | // Tests the exact text used to note the candidates |
| 71 | namespace test1 { |
| 72 | class A { |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 73 | 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}} |
| 74 | void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}} |
John McCall | adbb8f8 | 2010-01-13 09:16:55 +0000 | [diff] [blame] | 75 | void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}} |
| 76 | void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}} |
| 77 | void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}} |
| 78 | void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} |
| 79 | 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}} |
John McCall | e81e15e | 2010-01-14 00:56:20 +0000 | [diff] [blame] | 80 | |
Chris Lattner | 0c42bb6 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 81 | void bar(double d); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}} |
| 82 | void bar(int i); //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}} |
John McCall | 651f3ee | 2010-01-14 03:28:57 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 0c42bb6 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 84 | void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}} |
| 85 | void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}} |
John McCall | adbb8f8 | 2010-01-13 09:16:55 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | void test() { |
| 89 | A a; |
| 90 | a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}} |
John McCall | e81e15e | 2010-01-14 00:56:20 +0000 | [diff] [blame] | 91 | |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 92 | const A b = A(); |
John McCall | e81e15e | 2010-01-14 00:56:20 +0000 | [diff] [blame] | 93 | b.bar(0); //expected-error {{no matching member function for call to 'bar'}} |
John McCall | 651f3ee | 2010-01-14 03:28:57 +0000 | [diff] [blame] | 94 | |
| 95 | a.baz(b); //expected-error {{no matching member function for call to 'baz'}} |
John McCall | adbb8f8 | 2010-01-13 09:16:55 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |