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