annotate clang/test/SemaCXX/namespace-alias.cpp @ 222:81f6424ef0e3 llvm-original

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