| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
namespace N { struct X { }; }; |
| 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'}} |
| 12 |
|
| 13 |
int i; |
| 14 |
namespace D = |
| 15 |
i; // expected-error {{expected namespace name}} |
| 16 |
|
| 17 |
namespace E1 = N:: |
| 18 |
Foo; // expected-error {{expected namespace name}} |
| 19 |
namespace E2 = N:: |
| 20 |
X; // expected-error {{expected namespace name}} |
| 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 |
} |
| 28 |
|
| 29 |
namespace G { |
| 30 |
namespace B = N; |
| 31 |
} |
| 32 |
|
| 33 |
namespace H { |
| 34 |
namespace A1 { } |
| 35 |
namespace A2 { } |
| 36 |
|
| 37 |
// These all point to A1. |
| 38 |
namespace B = A1; |
| 39 |
namespace B = A1; |
| 40 |
namespace C = B; |
| 41 |
namespace B = C; // expected-note {{previously defined as an alias for 'A1'}} |
| 42 |
|
| 43 |
namespace B = A2; // expected-error {{redefinition of 'B' as an alias for a different namespace}} |
| 44 |
} |
| 45 |
|
| 46 |
namespace I { |
| 47 |
namespace A1 { int i; } |
| 48 |
|
| 49 |
namespace A2 = A1; |
| 50 |
|
| 51 |
namespace A3::extra::specifiers = A2; // expected-error {{alias must be a single identifier}} |
| 52 |
} |
| 53 |
|
| 54 |
int f() { |
| 55 |
return I::A2::i; |
| 56 |
} |
| 57 |
|
| 58 |
namespace J { |
| 59 |
namespace A { |
| 60 |
namespace B { void func (); } |
| 61 |
} |
| 62 |
|
| 63 |
namespace C = A; |
| 64 |
|
| 65 |
using namespace C::B; |
| 66 |
|
| 67 |
void g() { |
| 68 |
func(); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
namespace K { |
| 73 |
namespace KA { void func(); } |
| 74 |
|
| 75 |
void f() { |
| 76 |
namespace KB = KA; |
| 77 |
KB::func(); |
| 78 |
} |
| 79 |
|
| 80 |
template <class T> void g() { |
| 81 |
namespace KC = KA; |
| 82 |
KC::func(); |
| 83 |
} |
| 84 |
template void g<int>(); |
| 85 |
template void g<long>(); |
| 86 |
|
| 87 |
void h() { |
| 88 |
KB::func(); // expected-error {{undeclared identifier 'KB'}} |
| 89 |
KC::func(); // expected-error {{undeclared identifier 'KC'}} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
namespace { |
| 94 |
class C1; |
| 95 |
} |
| 96 |
namespace { |
| 97 |
class C1; |
| 98 |
} |
| 99 |
C1 *pc1 = 0; |
| 100 |
|
| 101 |
namespace N { |
| 102 |
namespace { |
| 103 |
class C2; |
| 104 |
} |
| 105 |
} |
| 106 |
namespace N { |
| 107 |
namespace { |
| 108 |
class C2; |
| 109 |
} |
| 110 |
} |
| 111 |
N::C2 *pc2 = 0; |
| 112 |
|
| 113 |
// PR6341 |
| 114 |
namespace A = N; |
| 115 |
namespace N { } |
| 116 |
namespace A = N; |
| 117 |
|
| 118 |
A::X nx; |
| 119 |
|
| 120 |
namespace PR7014 { |
| 121 |
namespace X |
| 122 |
{ |
| 123 |
namespace Y {} |
| 124 |
} |
| 125 |
|
| 126 |
using namespace X; |
| 127 |
|
| 128 |
namespace Y = X::Y; |
| 129 |
} |
| 130 |
|
| 131 |
namespace PR25731 { |
| 132 |
void f() { |
| 133 |
namespace X = PR25731; |
| 134 |
namespace X = PR25731; |
| 135 |
X::f(); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
namespace MultipleUnambiguousLookupResults { |
| 140 |
namespace A { int y; } |
| 141 |
namespace B { |
| 142 |
namespace X { int x; } |
| 143 |
namespace Y = A; |
| 144 |
namespace Z = A; // expected-note {{candidate}} |
| 145 |
} |
| 146 |
namespace C { |
| 147 |
namespace X = B::X; |
| 148 |
namespace Y = A; |
| 149 |
namespace Z = X; // expected-note {{candidate}} |
| 150 |
} |
| 151 |
using namespace B; |
| 152 |
using namespace C; |
| 153 |
int x1 = X::x; // ok, unambiguous |
| 154 |
int y1 = Y::y; // ok, unambiguous |
| 155 |
int z1 = Z::x; // expected-error {{ambiguous}} |
| 156 |
|
| 157 |
namespace X = C::X; |
| 158 |
namespace Y = A; |
| 159 |
int x2 = X::x; // ok, unambiguous |
| 160 |
int y2 = Y::y; // ok, unambiguous |
| 161 |
} |
| 162 |
|
| 163 |
namespace RedeclOfNonNamespace { |
| 164 |
int a; // expected-note {{previous}} |
| 165 |
namespace X { int b; } |
| 166 |
using X::b; // expected-note {{previous}} |
| 167 |
namespace c {} // expected-note {{previous}} |
| 168 |
|
| 169 |
namespace a = X; // expected-error {{different kind}} |
| 170 |
namespace b = X; // expected-error {{different kind}} |
| 171 |
namespace c = X; // expected-error-re {{redefinition of 'c'{{$}}}} |
| 172 |
} |