| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
namespace N { |
| 4 |
struct X { }; |
| 5 |
|
| 6 |
X operator+(X, X); |
| 7 |
|
| 8 |
void f(X); // expected-note 2 {{'N::f' declared here}} |
| 9 |
void g(X); // expected-note{{candidate function}} |
| 10 |
|
| 11 |
void test_multiadd(X x) { |
| 12 |
(void)(x + x); |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
namespace M { |
| 17 |
struct Y : N::X { }; |
| 18 |
} |
| 19 |
|
| 20 |
void f(); |
| 21 |
|
| 22 |
void test_operator_adl(N::X x, M::Y y) { |
| 23 |
(void)(x + x); |
| 24 |
(void)(y + y); |
| 25 |
} |
| 26 |
|
| 27 |
void test_func_adl(N::X x, M::Y y) { |
| 28 |
f(x); |
| 29 |
f(y); |
| 30 |
(f)(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}} |
| 31 |
::f(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}} |
| 32 |
} |
| 33 |
|
| 34 |
namespace N { |
| 35 |
void test_multiadd2(X x) { |
| 36 |
(void)(x + x); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
void test_func_adl_only(N::X x) { |
| 42 |
g(x); |
| 43 |
} |
| 44 |
|
| 45 |
namespace M { |
| 46 |
int g(N::X); // expected-note{{candidate function}} |
| 47 |
|
| 48 |
void test(N::X x) { |
| 49 |
g(x); // expected-error{{call to 'g' is ambiguous}} |
| 50 |
int i = (g)(x); |
| 51 |
|
| 52 |
int g(N::X); |
| 53 |
g(x); // okay; calls locally-declared function, no ADL |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
void test_operator_name_adl(N::X x) { |
| 59 |
(void)operator+(x, x); |
| 60 |
} |
| 61 |
|
| 62 |
struct Z { }; |
| 63 |
int& f(Z); |
| 64 |
|
| 65 |
namespace O { |
| 66 |
char &f(); |
| 67 |
void test_global_scope_adl(Z z) { |
| 68 |
{ |
| 69 |
int& ir = f(z); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
extern "C" { |
| 75 |
struct L { int x; }; |
| 76 |
} |
| 77 |
|
| 78 |
void h(L); // expected-note{{candidate function}} |
| 79 |
|
| 80 |
namespace P { |
| 81 |
void h(L); // expected-note{{candidate function}} |
| 82 |
void test_transparent_context_adl(L l) { |
| 83 |
{ |
| 84 |
h(l); // expected-error {{call to 'h' is ambiguous}} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
namespace test5 { |
| 90 |
namespace NS { |
| 91 |
struct A; |
| 92 |
void foo(void (*)(A&)); |
| 93 |
} |
| 94 |
void bar(NS::A& a); |
| 95 |
|
| 96 |
void test() { |
| 97 |
foo(&bar); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
// PR6762: __builtin_va_list should be invisible to ADL on all platforms. |
| 102 |
void test6_function(__builtin_va_list &argv); |
| 103 |
namespace test6 { |
| 104 |
void test6_function(__builtin_va_list &argv); |
| 105 |
|
| 106 |
void test() { |
| 107 |
__builtin_va_list args; |
| 108 |
test6_function(args); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
// PR13682: we might need to instantiate class temploids. |
| 113 |
namespace test7 { |
| 114 |
namespace inner { |
| 115 |
class A {}; |
| 116 |
void test7_function(A &); |
| 117 |
} |
| 118 |
template <class T> class B : public inner::A {}; |
| 119 |
|
| 120 |
void test(B<int> &ref) { |
| 121 |
test7_function(ref); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
// Like test7, but ensure we don't complain if the type is properly |
| 126 |
// incomplete. |
| 127 |
namespace test8 { |
| 128 |
template <class T> class B; |
| 129 |
void test8_function(B<int> &); |
| 130 |
|
| 131 |
void test(B<int> &ref) { |
| 132 |
test8_function(ref); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
// [...] Typedef names and using-declarations used to specify the types |
| 139 |
// do not contribute to this set. |
| 140 |
namespace typedef_names_and_using_declarations { |
| 141 |
namespace N { struct S {}; void f(S); } |
| 142 |
namespace M { typedef N::S S; void g1(S); } // expected-note {{declared here}} |
| 143 |
namespace L { using N::S; void g2(S); } // expected-note {{declared here}} |
| 144 |
void test() { |
| 145 |
M::S s; |
| 146 |
f(s); // ok |
| 147 |
g1(s); // expected-error {{use of undeclared}} |
| 148 |
g2(s); // expected-error {{use of undeclared}} |
| 149 |
} |
| 150 |
} |