| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
// C++03 [namespace.udecl]p11: (per DR101) |
| 4 |
// If a function declaration in namespace scope or block scope has |
| 5 |
// the same name and the same parameter types as a function |
| 6 |
// introduced by a using-declaration, and the declarations do not declare the |
| 7 |
// same function, the program is ill-formed. [Note: two using-declarations may |
| 8 |
// introduce functions with the same name and the same parameter types. If, |
| 9 |
// for a call to an unqualified function name, function overload resolution |
| 10 |
// selects the functions introduced by such using-declarations, the function |
| 11 |
// call is ill-formed.] |
| 12 |
// |
| 13 |
// FIXME: DR565 introduces parallel wording here for function templates. |
| 14 |
|
| 15 |
namespace test0 { |
| 16 |
namespace ns { void foo(); } // expected-note {{target of using declaration}} |
| 17 |
int foo(void); // expected-note {{conflicting declaration}} |
| 18 |
using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} |
| 19 |
} |
| 20 |
|
| 21 |
namespace test1 { |
| 22 |
namespace ns { void foo(); } // expected-note {{target of using declaration}} |
| 23 |
using ns::foo; //expected-note {{using declaration}} |
| 24 |
int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} |
| 25 |
} |
| 26 |
|
| 27 |
namespace test2 { |
| 28 |
namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} |
| 29 |
void test0() { |
| 30 |
int foo(void); // expected-note {{conflicting declaration}} |
| 31 |
using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} |
| 32 |
} |
| 33 |
|
| 34 |
void test1() { |
| 35 |
using ns::foo; //expected-note {{using declaration}} |
| 36 |
int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
namespace test3 { |
| 41 |
namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} |
| 42 |
class Test0 { |
| 43 |
void test() { |
| 44 |
int foo(void); // expected-note {{conflicting declaration}} |
| 45 |
using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
class Test1 { |
| 50 |
void test() { |
| 51 |
using ns::foo; //expected-note {{using declaration}} |
| 52 |
int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} |
| 53 |
} |
| 54 |
}; |
| 55 |
} |
| 56 |
|
| 57 |
namespace test4 { |
| 58 |
namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} |
| 59 |
template <typename> class Test0 { |
| 60 |
void test() { |
| 61 |
int foo(void); // expected-note {{conflicting declaration}} |
| 62 |
using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
template <typename> class Test1 { |
| 67 |
void test() { |
| 68 |
using ns::foo; //expected-note {{using declaration}} |
| 69 |
int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} |
| 70 |
} |
| 71 |
}; |
| 72 |
} |
| 73 |
|
| 74 |
// FIXME: we should be able to diagnose both of these, but we can't. |
| 75 |
namespace test5 { |
| 76 |
namespace ns { void foo(int); } |
| 77 |
template <typename T> class Test0 { |
| 78 |
void test() { |
| 79 |
int foo(T); |
| 80 |
using ns::foo; |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
template <typename T> class Test1 { |
| 85 |
void test() { |
| 86 |
using ns::foo; |
| 87 |
int foo(T); |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
template class Test0<int>; |
| 92 |
template class Test1<int>; |
| 93 |
} |
| 94 |
|
| 95 |
namespace test6 { |
| 96 |
namespace ns { void foo(); } // expected-note {{target of using declaration}} |
| 97 |
using ns::foo; // expected-note {{using declaration}} |
| 98 |
namespace ns { |
| 99 |
using test6::foo; |
| 100 |
void foo() {} |
| 101 |
} |
| 102 |
void foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} |
| 103 |
} |
| 104 |
|
| 105 |
namespace test7 { |
| 106 |
void foo(); |
| 107 |
using test7::foo; |
| 108 |
void foo() {} |
| 109 |
} |