xref: /llvm-project/clang/test/SemaCXX/namespace-alias.cpp (revision bb1e4724f1a2042e36bd42acf8ce040e867cfdf2)
1 // RUN: clang-cc -fsyntax-only -verify %s
2 
3 namespace N { };
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 = i; // expected-error {{expected namespace name}}
15 
16 namespace E = N::Foo; // expected-error {{expected namespace name}}
17 
18 namespace F {
19   namespace A { namespace B { } } // expected-note {{candidate found by name lookup is 'F::A::B'}}
20   namespace B { } // expected-note {{candidate found by name lookup is 'F::B'}}
21   using namespace A;
22   namespace D = B; // expected-error {{reference to 'B' is ambiguous}}
23 }
24 
25 namespace G {
26   namespace B = N;
27 }
28 
29 namespace H {
30   namespace A1 { }
31   namespace A2 { }
32 
33   // These all point to A1.
34   namespace B = A1; // expected-note {{previous definition is here}}
35   namespace B = A1;
36   namespace C = B;
37   namespace B = C;
38 
39   namespace B = A2; // expected-error {{redefinition of 'B' as different kind of symbol}}
40 }
41 
42 namespace I {
43   namespace A1 { int i; }
44 
45   namespace A2 = A1;
46 }
47 
48 int f() {
49   return I::A2::i;
50 }
51