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 // C++03 [namespace.udecl]p4:
6 // A using-declaration used as a member-declaration shall refer to a
7 // member of a base class of the class being defined, shall refer to
8 // a member of an anonymous union that is a member of a base class
9 // of the class being defined, or shall refer to an enumerator for
10 // an enumeration type that is a member of a base class of the class
13 // There is no directly analogous paragraph in C++0x, and the feature
14 // works sufficiently differently there that it needs a separate test.
21 static union { double union_member
; };
22 enum tagname
{ enumerator
};
26 using NonClass::type
; // expected-error {{not a class}}
27 using NonClass::hiding
; // expected-error {{not a class}}
28 using NonClass::union_member
; // expected-error {{not a class}}
29 using NonClass::enumerator
; // expected-error {{not a class}}
38 struct hiding
{}; // expected-note {{previous use is here}}
40 union { double union_member
; };
41 enum tagname
{ enumerator
};
47 using A::union_member
;
56 typedef struct A::hiding local
;
57 struct hiding _
= local();
61 union hiding _
; // expected-error {{tag type that does not match previous}}
65 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
69 enum tagname _
= enumerator
;
81 struct hiding
{}; // expected-note {{previous use is here}}
83 union { double union_member
; };
84 enum tagname
{ enumerator
};
87 template <class T
> struct B
: A
{
90 using A::union_member
;
99 typedef struct A::hiding local
;
100 struct hiding _
= local();
104 union hiding _
; // expected-error {{tag type that does not match previous}}
108 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
112 enum tagname _
= enumerator
;
124 template <class T
> struct A
{
125 typedef int type
; // expected-note {{target of using declaration}}
127 Opaque0 hiding
; // expected-note {{target of using declaration}}
128 union { double union_member
; }; // expected-note {{target of using declaration}}
129 enum tagname
{ enumerator
}; // expected-note 2 {{target of using declaration}}
132 template <class T
> struct B
: A
<T
> {
133 using A
<T
>::type
; // expected-error {{dependent using declaration resolved to type without 'typename'}}
135 using A
<T
>::union_member
;
136 using A
<T
>::enumerator
;
137 using A
<T
>::tagname
; // expected-error {{dependent using declaration resolved to type without 'typename'}}
139 // FIXME: re-enable these when the various bugs involving tags are fixed
142 typedef struct A
<T
>::hiding local
;
143 struct hiding _
= local();
147 typedef struct A
<T
>::hiding local
;
148 union hiding _
= local();
153 char array
[sizeof(union_member
) == sizeof(double) ? 1 : -1];
158 enum tagname _
= enumerator
;
167 template struct B
<int>; // expected-note {{in instantiation}}
169 template <class T
> struct C
: A
<T
> {
170 using typename A
<T
>::type
;
171 using typename A
<T
>::hiding
; // expected-note {{declared here}} \
172 // expected-error {{'typename' keyword used on a non-type}}
173 using typename A
<T
>::union_member
; // expected-error {{'typename' keyword used on a non-type}}
174 using typename A
<T
>::enumerator
; // expected-error {{'typename' keyword used on a non-type}}
181 Opaque0 _
= hiding
; // expected-error {{does not refer to a value}}
185 template struct C
<int>; // expected-note {{in instantiation}}
197 struct Subclass
: Base
{
204 // We should be able to diagnose these without instantiation.
205 template <class T
> struct C
: Base
{
206 using InnerNS::foo
; // expected-error {{not a class}}
207 using Base::bar
; // expected-error {{no member named 'bar'}}
208 using Unrelated::foo
; // expected-error {{not a base class}}
209 using C::foo
; // legal in C++03
210 using Subclass::foo
; // legal in C++03
211 #if __cplusplus >= 201103L
212 // expected-error@-3 {{refers to its own class}}
213 // expected-error@-3 {{refers into 'Subclass::', which is not a base class}}
217 #if __cplusplus < 201103L
218 // expected-note@-2 {{target of using declaration}}
220 using C::bar
; // expected-error {{refers to its own class}}
228 B
&operator=(const B
&);
231 #if __cplusplus >= 201103L