1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 // This is just the test for [namespace.udecl]p4 with 'using'
6 // uniformly stripped out.
8 // C++03 [namespace.udecl]p4:
9 // A using-declaration used as a member-declaration shall refer to a
10 // member of a base class of the class being defined, shall refer to
11 // a member of an anonymous union that is a member of a base class
12 // of the class being defined, or shall refer to an enumerator for
13 // an enumeration type that is a member of a base class of the class
16 // There is no directly analogous paragraph in C++0x, and the feature
17 // works sufficiently differently there that it needs a separate test.
24 static union { double union_member
; };
25 enum tagname
{ enumerator
};
29 NonClass::type
; // expected-error {{not a class}}
30 #if __cplusplus <= 199711L
31 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
33 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
36 NonClass::hiding
; // expected-error {{not a class}}
37 #if __cplusplus <= 199711L
38 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
40 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
43 NonClass::union_member
; // expected-error {{not a class}}
44 #if __cplusplus <= 199711L
45 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
47 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
50 NonClass::enumerator
; // expected-error {{not a class}}
51 #if __cplusplus <= 199711L
52 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
54 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
64 struct hiding
{}; // expected-note {{previous use is here}}
66 union { double union_member
; };
67 enum tagname
{ enumerator
};
72 #if __cplusplus <= 199711L
73 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
75 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
78 #if __cplusplus <= 199711L
79 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
81 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
85 #if __cplusplus <= 199711L
86 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
88 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
92 #if __cplusplus <= 199711L
93 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
95 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
99 #if __cplusplus <= 199711L
100 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
102 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
110 typedef struct A::hiding local
;
111 struct hiding _
= local();
115 union hiding _
; // expected-error {{tag type that does not match previous}}
119 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
123 enum tagname _
= enumerator
;
135 struct hiding
{}; // expected-note {{previous use is here}}
137 union { double union_member
; };
138 enum tagname
{ enumerator
};
141 template <class T
> struct B
: A
{
143 #if __cplusplus <= 199711L
144 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
146 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
150 #if __cplusplus <= 199711L
151 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
153 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
157 #if __cplusplus <= 199711L
158 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
160 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
164 #if __cplusplus <= 199711L
165 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
167 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
171 #if __cplusplus <= 199711L
172 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
174 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
182 typedef struct A::hiding local
;
183 struct hiding _
= local();
187 union hiding _
; // expected-error {{tag type that does not match previous}}
191 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
195 enum tagname _
= enumerator
;
207 template <class T
> struct A
{
208 typedef int type
; // expected-note {{target of using declaration}}
211 union { double union_member
; };
212 enum tagname
{ enumerator
}; // expected-note {{target of using declaration}}
215 template <class T
> struct B
: A
<T
> {
216 A
<T
>::type
; // expected-error {{dependent using declaration resolved to type without 'typename'}}
217 #if __cplusplus <= 199711L
218 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
220 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
224 #if __cplusplus <= 199711L
225 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
227 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
231 #if __cplusplus <= 199711L
232 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
234 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
238 #if __cplusplus <= 199711L
239 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
241 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
244 A
<T
>::tagname
; // expected-error {{dependent using declaration resolved to type without 'typename'}}
245 #if __cplusplus <= 199711L
246 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
248 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
251 // FIXME: re-enable these when the various bugs involving tags are fixed
254 typedef struct A
<T
>::hiding local
;
255 struct hiding _
= local();
259 typedef struct A
<T
>::hiding local
;
260 union hiding _
= local();
265 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
270 enum tagname _
= enumerator
;
279 template struct B
<int>; // expected-note {{in instantiation}}
291 struct Subclass
: Base
{
298 // We should be able to diagnose these without instantiation.
299 template <class T
> struct C
: Base
{
300 InnerNS::foo
; // expected-error {{not a class}}
301 #if __cplusplus <= 199711L
302 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
304 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
307 Base::bar
; // expected-error {{no member named 'bar'}}
308 #if __cplusplus <= 199711L
309 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
311 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
314 Unrelated::foo
; // expected-error {{not a base class}}
315 #if __cplusplus <= 199711L
316 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
318 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
321 C::foo
; // legal in C++03
322 #if __cplusplus <= 199711L
323 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
325 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
326 // expected-error@-5 {{using declaration refers to its own class}}
329 Subclass::foo
; // legal in C++03
330 #if __cplusplus <= 199711L
331 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
333 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
334 // expected-error@-5 {{using declaration refers into 'Subclass::', which is not a base class of 'C'}}
338 #if __cplusplus <= 199711L
339 //expected-note@-2 {{target of using declaration}}
342 #if __cplusplus <= 199711L
343 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
345 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
347 // expected-error@-6 {{using declaration refers to its own class}}