blob: 1c3da3c656a61afa25a0ac5b4e8cde6a2e127e96 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Anders Carlsson8d7ba402009-03-28 06:23:46 +00002
Douglas Gregorc67b0322010-03-26 22:59:39 +00003namespace N { struct X { }; };
Anders Carlsson8d7ba402009-03-28 06:23:46 +00004
5namespace A = N;
6
7int B; // expected-note {{previous definition is here}}
8namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}}
9
10namespace C { } // expected-note {{previous definition is here}}
11namespace C = N; // expected-error {{redefinition of 'C'}}
Anders Carlsson5721c682009-03-28 06:42:02 +000012
13int i;
14namespace D = i; // expected-error {{expected namespace name}}
15
16namespace E = N::Foo; // expected-error {{expected namespace name}}
Anders Carlssona1a1b302009-03-28 07:51:31 +000017
18namespace 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}
Anders Carlssondd729fc2009-03-28 23:49:35 +000024
25namespace G {
26 namespace B = N;
27}
Anders Carlsson81c85c42009-03-28 23:53:49 +000028
29namespace 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
42namespace I {
43 namespace A1 { int i; }
44
45 namespace A2 = A1;
46}
47
48int f() {
49 return I::A2::i;
50}
Anders Carlssonb73e75c2009-03-31 05:47:19 +000051
52namespace J {
53 namespace A {
54 namespace B { void func (); }
55 }
56
57 namespace C = A;
58
59 using namespace C::B;
60
61 void g() {
62 func();
63 }
64}
John McCall3dbd3d52010-02-16 06:53:13 +000065
66namespace K {
67 namespace KA { void func(); }
68
69 void f() {
70 namespace KB = KA;
71 KB::func();
72 }
73
74 template <class T> void g() {
75 namespace KC = KA;
76 KC::func();
77 }
78 template void g<int>();
79 template void g<long>();
80
81 void h() {
82 KB::func(); // expected-error {{undeclared identifier 'KB'}}
83 KC::func(); // expected-error {{undeclared identifier 'KC'}}
84 }
85}
Douglas Gregorc67b0322010-03-26 22:59:39 +000086
87// PR6341
88namespace A = N;
89namespace N { }
90namespace A = N;
91
92A::X nx;
93
Douglas Gregorae374752010-05-03 15:37:31 +000094namespace PR7014 {
95 namespace X
96 {
97 namespace Y {}
98 }
99
100 using namespace X;
101
102 namespace Y = X::Y;
103}