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