Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | 8d7ba40 | 2009-03-28 06:23:46 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | c67b032 | 2010-03-26 22:59:39 +0000 | [diff] [blame] | 3 | namespace N { struct X { }; }; |
Anders Carlsson | 8d7ba40 | 2009-03-28 06:23:46 +0000 | [diff] [blame] | 4 | |
| 5 | namespace A = N; |
| 6 | |
| 7 | int B; // expected-note {{previous definition is here}} |
| 8 | namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}} |
| 9 | |
| 10 | namespace C { } // expected-note {{previous definition is here}} |
| 11 | namespace C = N; // expected-error {{redefinition of 'C'}} |
Anders Carlsson | 5721c68 | 2009-03-28 06:42:02 +0000 | [diff] [blame] | 12 | |
| 13 | int i; |
| 14 | namespace D = i; // expected-error {{expected namespace name}} |
| 15 | |
| 16 | namespace E = N::Foo; // expected-error {{expected namespace name}} |
Anders Carlsson | a1a1b30 | 2009-03-28 07:51:31 +0000 | [diff] [blame] | 17 | |
| 18 | namespace F { |
| 19 | namespace A { namespace B { } } // expected-note {{candidate found by name lookup is 'F::A::B'}} |
| 20 | namespace B { } // expected-note {{candidate found by name lookup is 'F::B'}} |
| 21 | using namespace A; |
| 22 | namespace D = B; // expected-error {{reference to 'B' is ambiguous}} |
| 23 | } |
Anders Carlsson | dd729fc | 2009-03-28 23:49:35 +0000 | [diff] [blame] | 24 | |
| 25 | namespace G { |
| 26 | namespace B = N; |
| 27 | } |
Anders Carlsson | 81c85c4 | 2009-03-28 23:53:49 +0000 | [diff] [blame] | 28 | |
| 29 | namespace H { |
| 30 | namespace A1 { } |
| 31 | namespace A2 { } |
| 32 | |
| 33 | // These all point to A1. |
| 34 | namespace B = A1; // expected-note {{previous definition is here}} |
| 35 | namespace B = A1; |
| 36 | namespace C = B; |
| 37 | namespace B = C; |
| 38 | |
| 39 | namespace B = A2; // expected-error {{redefinition of 'B' as different kind of symbol}} |
| 40 | } |
| 41 | |
| 42 | namespace I { |
| 43 | namespace A1 { int i; } |
| 44 | |
| 45 | namespace A2 = A1; |
| 46 | } |
| 47 | |
| 48 | int f() { |
| 49 | return I::A2::i; |
| 50 | } |
Anders Carlsson | b73e75c | 2009-03-31 05:47:19 +0000 | [diff] [blame] | 51 | |
| 52 | namespace J { |
| 53 | namespace A { |
| 54 | namespace B { void func (); } |
| 55 | } |
| 56 | |
| 57 | namespace C = A; |
| 58 | |
| 59 | using namespace C::B; |
| 60 | |
| 61 | void g() { |
| 62 | func(); |
| 63 | } |
| 64 | } |
John McCall | 3dbd3d5 | 2010-02-16 06:53:13 +0000 | [diff] [blame] | 65 | |
| 66 | namespace K { |
| 67 | namespace KA { void func(); } |
| 68 | |
| 69 | void f() { |
| 70 | namespace KB = KA; |
| 71 | KB::func(); |
| 72 | } |
| 73 | |
| 74 | template <class T> void g() { |
| 75 | namespace KC = KA; |
| 76 | KC::func(); |
| 77 | } |
| 78 | template void g<int>(); |
| 79 | template void g<long>(); |
| 80 | |
| 81 | void h() { |
| 82 | KB::func(); // expected-error {{undeclared identifier 'KB'}} |
| 83 | KC::func(); // expected-error {{undeclared identifier 'KC'}} |
| 84 | } |
| 85 | } |
Douglas Gregor | c67b032 | 2010-03-26 22:59:39 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 87 | namespace { |
| 88 | class C1; |
| 89 | } |
| 90 | namespace { |
| 91 | class C1; |
| 92 | } |
| 93 | C1 *pc1 = 0; |
| 94 | |
| 95 | namespace N { |
| 96 | namespace { |
| 97 | class C2; |
| 98 | } |
| 99 | } |
| 100 | namespace N { |
| 101 | namespace { |
| 102 | class C2; |
| 103 | } |
| 104 | } |
| 105 | N::C2 *pc2 = 0; |
| 106 | |
Douglas Gregor | c67b032 | 2010-03-26 22:59:39 +0000 | [diff] [blame] | 107 | // PR6341 |
| 108 | namespace A = N; |
| 109 | namespace N { } |
| 110 | namespace A = N; |
| 111 | |
| 112 | A::X nx; |
| 113 | |
Douglas Gregor | ae37475 | 2010-05-03 15:37:31 +0000 | [diff] [blame] | 114 | namespace PR7014 { |
| 115 | namespace X |
| 116 | { |
| 117 | namespace Y {} |
| 118 | } |
| 119 | |
| 120 | using namespace X; |
| 121 | |
| 122 | namespace Y = X::Y; |
| 123 | } |