[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / namespace-alias.cpp
blob281ee9962e8b52e3457ee0f6565f17efab624d06
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 namespace N { struct X { }; };
5 namespace A = N;
7 int B; // expected-note {{previous definition is here}}
8 namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}}
10 namespace C { } // expected-note {{previous definition is here}}
11 namespace C = N; // expected-error {{redefinition of 'C'}}
13 int i;
14 namespace D =
15 i; // expected-error {{expected namespace name}}
17 namespace E1 = N::
18 Foo; // expected-error {{expected namespace name}}
19 namespace E2 = N::
20 X; // expected-error {{expected namespace name}}
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}}
29 namespace G {
30 namespace B = N;
33 namespace H {
34 namespace A1 { }
35 namespace A2 { }
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'}}
43 namespace B = A2; // expected-error {{redefinition of 'B' as an alias for a different namespace}}
46 namespace I {
47 namespace A1 { int i; }
49 namespace A2 = A1;
52 int f() {
53 return I::A2::i;
56 namespace J {
57 namespace A {
58 namespace B { void func (); }
61 namespace C = A;
63 using namespace C::B;
65 void g() {
66 func();
70 namespace K {
71 namespace KA { void func(); }
73 void f() {
74 namespace KB = KA;
75 KB::func();
78 template <class T> void g() {
79 namespace KC = KA;
80 KC::func();
82 template void g<int>();
83 template void g<long>();
85 void h() {
86 KB::func(); // expected-error {{undeclared identifier 'KB'}}
87 KC::func(); // expected-error {{undeclared identifier 'KC'}}
91 namespace {
92 class C1;
94 namespace {
95 class C1;
97 C1 *pc1 = 0;
99 namespace N {
100 namespace {
101 class C2;
104 namespace N {
105 namespace {
106 class C2;
109 N::C2 *pc2 = 0;
111 // PR6341
112 namespace A = N;
113 namespace N { }
114 namespace A = N;
116 A::X nx;
118 namespace PR7014 {
119 namespace X
121 namespace Y {}
124 using namespace X;
126 namespace Y = X::Y;
129 namespace PR25731 {
130 void f() {
131 namespace X = PR25731;
132 namespace X = PR25731;
133 X::f();
137 namespace MultipleUnambiguousLookupResults {
138 namespace A { int y; }
139 namespace B {
140 namespace X { int x; }
141 namespace Y = A;
142 namespace Z = A; // expected-note {{candidate}}
144 namespace C {
145 namespace X = B::X;
146 namespace Y = A;
147 namespace Z = X; // expected-note {{candidate}}
149 using namespace B;
150 using namespace C;
151 int x1 = X::x; // ok, unambiguous
152 int y1 = Y::y; // ok, unambiguous
153 int z1 = Z::x; // expected-error {{ambiguous}}
155 namespace X = C::X;
156 namespace Y = A;
157 int x2 = X::x; // ok, unambiguous
158 int y2 = Y::y; // ok, unambiguous
161 namespace RedeclOfNonNamespace {
162 int a; // expected-note {{previous}}
163 namespace X { int b; }
164 using X::b; // expected-note {{previous}}
165 namespace c {} // expected-note {{previous}}
167 namespace a = X; // expected-error {{different kind}}
168 namespace b = X; // expected-error {{different kind}}
169 namespace c = X; // expected-error-re {{redefinition of 'c'{{$}}}}