xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/namespace-alias.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc namespace N { struct X { }; };
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc namespace A = N;
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc int B; // expected-note {{previous definition is here}}
8*f4a2713aSLionel Sambuc namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}}
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc namespace C { } // expected-note {{previous definition is here}}
11*f4a2713aSLionel Sambuc namespace C = N; // expected-error {{redefinition of 'C'}}
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc int i;
14*f4a2713aSLionel Sambuc namespace D =
15*f4a2713aSLionel Sambuc i; // expected-error {{expected namespace name}}
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc namespace E1 = N::
18*f4a2713aSLionel Sambuc Foo; // expected-error {{expected namespace name}}
19*f4a2713aSLionel Sambuc namespace E2 = N::
20*f4a2713aSLionel Sambuc X; // expected-error {{expected namespace name}}
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc namespace F {
23*f4a2713aSLionel Sambuc   namespace A { namespace B { } } // expected-note {{candidate found by name lookup is 'F::A::B'}}
24*f4a2713aSLionel Sambuc   namespace B { } // expected-note {{candidate found by name lookup is 'F::B'}}
25*f4a2713aSLionel Sambuc   using namespace A;
26*f4a2713aSLionel Sambuc   namespace D = B; // expected-error {{reference to 'B' is ambiguous}}
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc namespace G {
30*f4a2713aSLionel Sambuc   namespace B = N;
31*f4a2713aSLionel Sambuc }
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc namespace H {
34*f4a2713aSLionel Sambuc   namespace A1 { }
35*f4a2713aSLionel Sambuc   namespace A2 { }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   // These all point to A1.
38*f4a2713aSLionel Sambuc   namespace B = A1; // expected-note {{previous definition is here}}
39*f4a2713aSLionel Sambuc   namespace B = A1;
40*f4a2713aSLionel Sambuc   namespace C = B;
41*f4a2713aSLionel Sambuc   namespace B = C;
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc   namespace B = A2; // expected-error {{redefinition of 'B' as different kind of symbol}}
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc namespace I {
47*f4a2713aSLionel Sambuc   namespace A1 { int i; }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc   namespace A2 = A1;
50*f4a2713aSLionel Sambuc }
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc int f() {
53*f4a2713aSLionel Sambuc   return I::A2::i;
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc namespace J {
57*f4a2713aSLionel Sambuc   namespace A {
58*f4a2713aSLionel Sambuc     namespace B { void func (); }
59*f4a2713aSLionel Sambuc   }
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc   namespace C = A;
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc   using namespace C::B;
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc   void g() {
66*f4a2713aSLionel Sambuc     func();
67*f4a2713aSLionel Sambuc   }
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc namespace K {
71*f4a2713aSLionel Sambuc   namespace KA { void func(); }
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc   void f() {
74*f4a2713aSLionel Sambuc     namespace KB = KA;
75*f4a2713aSLionel Sambuc     KB::func();
76*f4a2713aSLionel Sambuc   }
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc   template <class T> void g() {
79*f4a2713aSLionel Sambuc     namespace KC = KA;
80*f4a2713aSLionel Sambuc     KC::func();
81*f4a2713aSLionel Sambuc   }
82*f4a2713aSLionel Sambuc   template void g<int>();
83*f4a2713aSLionel Sambuc   template void g<long>();
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc   void h() {
86*f4a2713aSLionel Sambuc     KB::func(); // expected-error {{undeclared identifier 'KB'}}
87*f4a2713aSLionel Sambuc     KC::func(); // expected-error {{undeclared identifier 'KC'}}
88*f4a2713aSLionel Sambuc   }
89*f4a2713aSLionel Sambuc }
90*f4a2713aSLionel Sambuc 
91*f4a2713aSLionel Sambuc namespace {
92*f4a2713aSLionel Sambuc   class C1;
93*f4a2713aSLionel Sambuc }
94*f4a2713aSLionel Sambuc namespace {
95*f4a2713aSLionel Sambuc   class C1;
96*f4a2713aSLionel Sambuc }
97*f4a2713aSLionel Sambuc C1 *pc1 = 0;
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc namespace N {
100*f4a2713aSLionel Sambuc   namespace {
101*f4a2713aSLionel Sambuc     class C2;
102*f4a2713aSLionel Sambuc   }
103*f4a2713aSLionel Sambuc }
104*f4a2713aSLionel Sambuc namespace N {
105*f4a2713aSLionel Sambuc   namespace {
106*f4a2713aSLionel Sambuc     class C2;
107*f4a2713aSLionel Sambuc   }
108*f4a2713aSLionel Sambuc }
109*f4a2713aSLionel Sambuc N::C2 *pc2 = 0;
110*f4a2713aSLionel Sambuc 
111*f4a2713aSLionel Sambuc // PR6341
112*f4a2713aSLionel Sambuc namespace A = N;
113*f4a2713aSLionel Sambuc namespace N { }
114*f4a2713aSLionel Sambuc namespace A = N;
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc A::X nx;
117*f4a2713aSLionel Sambuc 
118*f4a2713aSLionel Sambuc namespace PR7014 {
119*f4a2713aSLionel Sambuc   namespace X
120*f4a2713aSLionel Sambuc   {
121*f4a2713aSLionel Sambuc     namespace Y {}
122*f4a2713aSLionel Sambuc   }
123*f4a2713aSLionel Sambuc 
124*f4a2713aSLionel Sambuc   using namespace X;
125*f4a2713aSLionel Sambuc 
126*f4a2713aSLionel Sambuc   namespace Y = X::Y;
127*f4a2713aSLionel Sambuc }
128