]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/nested-name-spec.cpp
Updaet clang to 92395.
[FreeBSD/FreeBSD.git] / test / SemaCXX / nested-name-spec.cpp
1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s 
2 namespace A {
3   struct C {
4     static int cx;
5
6     static int cx2;
7
8     static int Ag1();
9     static int Ag2();
10   };
11   int ax;
12   void Af();
13 }
14
15 A:: ; // expected-error {{expected unqualified-id}}
16 ::A::ax::undef ex3; // expected-error {{no member named}}
17 A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}}
18
19 int A::C::Ag1() { return 0; }
20
21 static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
22
23 int A::C::cx = 17;
24
25
26 static int A::C::cx2 = 17; // expected-error{{'static' can}}
27
28 class C2 {
29   void m(); // expected-note{{member declaration nearly matches}}
30
31   void f(const int& parm); // expected-note{{member declaration nearly matches}}
32   void f(int) const; // expected-note{{member declaration nearly matches}}
33   void f(float);
34
35   int x;
36 };
37
38 void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'class C2'}}
39
40 void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'class C2'}}
41
42 void C2::m() {
43   x = 0;
44 }
45
46 namespace B {
47   void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
48 }
49
50 void f1() {
51   void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
52 }
53
54 void f2() {
55   A:: ; // expected-error {{expected unqualified-id}}
56   A::C::undef = 0; // expected-error {{no member named 'undef'}}
57   ::A::C::cx = 0;
58   int x = ::A::ax = A::C::cx;
59   x = sizeof(A::C);
60   x = sizeof(::A::C::cx);
61 }
62
63 A::C c1;
64 struct A::C c2;
65 struct S : public A::C {};
66 struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
67
68 namespace A2 {
69   typedef int INT;
70   struct RC;
71   struct CC {
72     struct NC;
73   };
74 }
75
76 struct A2::RC {
77   INT x;
78 };
79
80 struct A2::CC::NC {
81   void m() {}
82 };
83
84 void f3() {
85   N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
86   int N;
87   N::x = 0; // expected-error {{expected a class or namespace}}
88   { int A;           A::ax = 0; }
89   { typedef int A;   A::ax = 0; } // expected-error{{expected a class or namespace}}
90   { typedef A::C A;  A::ax = 0; } // expected-error {{no member named 'ax'}}
91   { typedef A::C A;  A::cx = 0; }
92 }
93
94 // make sure the following doesn't hit any asserts
95 void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
96                       expected-error {{variable has incomplete type 'void'}}
97
98 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
99
100 void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
101
102 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
103
104 void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
105
106
107 namespace E {
108   int X = 5;
109   
110   namespace Nested {
111     enum E {
112       X = 0
113     };
114
115     void f() {
116       return E::X; // expected-error{{expected a class or namespace}}
117     }
118   }
119 }
120
121
122 class Operators {
123   Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
124   operator bool();
125 };
126
127 Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'class Operators'}}
128   Operators ops;
129   return ops;
130 }
131
132 Operators Operators::operator+(const Operators&) const {
133   Operators ops;
134   return ops;
135 }
136
137 Operators::operator bool() {
138   return true;
139 }
140
141 namespace A {
142   void g(int&); // expected-note{{member declaration nearly matches}}
143
144
145 void A::f() {} // expected-error{{out-of-line definition of 'f' does not match any declaration in namespace 'A'}}
146
147 void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}
148
149 struct Struct { };
150
151 void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'struct Struct'}}
152
153 void global_func(int);
154 void global_func2(int);
155
156 namespace N {
157   void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
158
159   void f();
160   // FIXME: if we move this to a separate definition of N, things break!
161 }
162 void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
163
164 void N::f() { } // okay
165
166 struct Y;  // expected-note{{forward declaration of 'struct Y'}}
167 Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name specifier}} \
168          // expected-error{{no type named 'foo' in}}
169
170 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
171       // expected-error{{C++ requires a type specifier for all declarations}} \
172       // expected-error{{only constructors take base initializers}}
173
174 struct foo_S {
175   static bool value;
176 };
177 bool (foo_S::value);
178
179
180 namespace somens {
181   struct a { }; // expected-note{{candidate function}}
182 }
183
184 template <typename T>
185 class foo {
186 };
187
188
189 // PR4452 / PR4451
190 foo<somens:a> a2;  // expected-error {{unexpected ':' in nested name specifier}}
191
192 somens::a a3 = a2; // expected-error {{no viable conversion}}
193
194 // typedefs and using declarations.
195 namespace test1 {
196   namespace ns {
197     class Counter { static int count; };
198     typedef Counter counter;
199   }
200   using ns::counter;
201
202   class Test {
203     void test1() {
204       counter c;
205       c.count++;
206       counter::count++;
207     }
208   };
209 }
210
211 // We still need to do lookup in the lexical scope, even if we push a
212 // non-lexical scope.
213 namespace test2 {
214   namespace ns {
215     int *count_ptr;
216   }
217   namespace {
218     int count = 0;
219   }
220
221   int *ns::count_ptr = &count;
222 }