Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 2 | |
| 3 | namespace A { |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 4 | short i; // expected-note 2{{candidate found by name lookup is 'A::i'}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 5 | namespace B { |
| 6 | long i; // expected-note{{candidate found by name lookup is 'A::B::i'}} |
| 7 | void f() {} // expected-note{{candidate function}} |
| 8 | int k; |
| 9 | namespace E {} // \ |
| 10 | expected-note{{candidate found by name lookup is 'A::B::E'}} |
| 11 | } |
| 12 | |
| 13 | namespace E {} // expected-note{{candidate found by name lookup is 'A::E'}} |
| 14 | |
| 15 | namespace C { |
| 16 | using namespace B; |
| 17 | namespace E {} // \ |
| 18 | expected-note{{candidate found by name lookup is 'A::C::E'}} |
| 19 | } |
| 20 | |
| 21 | void f() {} // expected-note{{candidate function}} |
| 22 | |
| 23 | class K1 { |
| 24 | void foo(); |
| 25 | }; |
| 26 | |
| 27 | void local_i() { |
| 28 | char i; |
| 29 | using namespace A; |
| 30 | using namespace B; |
| 31 | int a[sizeof(i) == sizeof(char)? 1 : -1]; // okay |
| 32 | } |
| 33 | namespace B { |
| 34 | int j; |
| 35 | } |
| 36 | |
| 37 | void ambig_i() { |
| 38 | using namespace A; |
| 39 | using namespace A::B; |
| 40 | (void) i; // expected-error{{reference to 'i' is ambiguous}} |
| 41 | f(); // expected-error{{call to 'f' is ambiguous}} |
| 42 | (void) j; // okay |
| 43 | using namespace C; |
| 44 | (void) k; // okay |
| 45 | using namespace E; // expected-error{{reference to 'E' is ambiguous}} |
| 46 | } |
| 47 | |
John McCall | 6654294 | 2009-11-18 23:05:13 +0000 | [diff] [blame] | 48 | struct K2 {}; // expected-note 2{{candidate found by name lookup is 'A::K2'}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 49 | } |
| 50 | |
John McCall | 6654294 | 2009-11-18 23:05:13 +0000 | [diff] [blame] | 51 | struct K2 {}; // expected-note 2{{candidate found by name lookup is 'K2'}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 52 | |
| 53 | using namespace A; |
| 54 | |
| 55 | void K1::foo() {} // okay |
| 56 | |
John McCall | 6826314 | 2009-11-18 22:49:29 +0000 | [diff] [blame] | 57 | struct K2 *k2; // expected-error{{reference to 'K2' is ambiguous}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 58 | |
John McCall | 6654294 | 2009-11-18 23:05:13 +0000 | [diff] [blame] | 59 | K2 *k3; // expected-error{{reference to 'K2' is ambiguous}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 60 | |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 61 | class X { // expected-note{{candidate found by name lookup is 'X'}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 62 | // FIXME: produce a suitable error message for this |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 63 | using namespace A; // expected-error{{not allowed}} |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | namespace N { |
Douglas Gregor | e2c565d | 2009-02-03 19:26:08 +0000 | [diff] [blame] | 67 | struct K2; |
| 68 | struct K2 { }; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 69 | } |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 70 | |
| 71 | namespace Ni { |
| 72 | int i(); // expected-note{{candidate found by name lookup is 'Ni::i'}} |
| 73 | } |
| 74 | |
| 75 | namespace NiTest { |
| 76 | using namespace A; |
| 77 | using namespace Ni; |
| 78 | |
| 79 | int test() { |
| 80 | return i; // expected-error{{reference to 'i' is ambiguous}} |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | namespace OneTag { |
| 85 | struct X; // expected-note{{candidate found by name lookup is 'OneTag::X'}} |
| 86 | } |
| 87 | |
| 88 | namespace OneFunction { |
| 89 | void X(); // expected-note{{candidate found by name lookup is 'OneFunction::X'}} |
| 90 | } |
| 91 | |
| 92 | namespace TwoTag { |
Douglas Gregor | 841b53c | 2009-04-13 15:14:38 +0000 | [diff] [blame] | 93 | struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}} |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | namespace FuncHidesTagAmbiguity { |
| 97 | using namespace OneTag; |
| 98 | using namespace OneFunction; |
| 99 | using namespace TwoTag; |
| 100 | |
| 101 | void test() { |
Douglas Gregor | 841b53c | 2009-04-13 15:14:38 +0000 | [diff] [blame] | 102 | (void)X(); // expected-error{{reference to 'X' is ambiguous}} |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 105 | |
| 106 | // PR5479 |
| 107 | namespace Aliased { |
| 108 | void inAliased(); |
| 109 | } |
| 110 | namespace Alias = Aliased; |
| 111 | using namespace Alias; |
| 112 | void testAlias() { |
| 113 | inAliased(); |
| 114 | } |
Douglas Gregor | 1237259 | 2009-12-08 15:38:36 +0000 | [diff] [blame] | 115 | |
| 116 | namespace N { void f2(int); } |
| 117 | |
| 118 | extern "C++" { |
| 119 | using namespace N; |
| 120 | void f3() { f2(1); } |
| 121 | } |
| 122 | |
| 123 | void f4() { f2(1); } |