1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
3 // RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
4 // RUN: not %clang_cc1 -fsyntax-only -std=c++98 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX98 %s
5 // RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX11 %s
14 using X::i
; // expected-error{{using declaration cannot refer to class member}}
15 using X::s
; // expected-error{{using declaration cannot refer to class member}}
16 using X::e
; // expected-error{{using declaration cannot refer to class member}}
17 using X::E::e
; // expected-error{{using declaration cannot refer to class member}} expected-warning 0-1{{C++11}}
18 #if __cplusplus < 201103L
19 // expected-note@-3 {{use a const variable}}
20 // expected-note@-3 {{use a const variable}}
21 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
22 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
24 // expected-note@-8 {{use a constexpr variable}}
25 // expected-note@-8 {{use a constexpr variable}}
26 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:1-[[@LINE-10]]:6}:"constexpr auto e = "
27 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:1-[[@LINE-10]]:6}:"constexpr auto e = "
31 using X::i
; // expected-error{{using declaration cannot refer to class member}}
32 using X::s
; // expected-error{{using declaration cannot refer to class member}}
33 using X::e
; // expected-error{{using declaration cannot refer to class member}}
34 using X::E::e
; // expected-error{{using declaration cannot refer to class member}} expected-warning 0-1{{C++11}}
35 #if __cplusplus < 201103L
36 // expected-note@-3 {{use a const variable}}
37 // expected-note@-3 {{use a const variable}}
38 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
39 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
41 // expected-note@-8 {{use a constexpr variable}}
42 // expected-note@-8 {{use a constexpr variable}}
43 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:3-[[@LINE-10]]:8}:"constexpr auto e = "
44 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:3-[[@LINE-10]]:8}:"constexpr auto e = "
49 struct A
{ int member
; };
50 struct B
{ static int member
; };
55 static void StaticFun() {
56 using T::member
; // expected-error 2{{class member}} expected-note {{use a reference instead}}
57 #if __cplusplus < 201103L
58 // expected-error@-2 {{cannot be used prior to '::'}}
65 static void StaticFun() {
66 using T::member
; // expected-error 2{{class member}} expected-note {{use a reference instead}}
72 X
<A
>::StaticFun(); // expected-note {{instantiation of}}
73 X
<B
>::StaticFun(); // expected-note {{instantiation of}}
75 #if __cplusplus < 201103L
76 // expected-note@-2 {{instantiation of}}
78 Y
<A
>::StaticFun(); // expected-note {{instantiation of}}
79 Y
<B
>::StaticFun(); // expected-note {{instantiation of}}
82 template<typename T
, typename U
> void value_vs_value() {
83 using T::a
; // expected-note {{previous}}
84 #if __cplusplus < 201103L
85 // expected-error@-2 {{cannot be used prior to '::'}}
87 extern int a(); // expected-error {{different kind of symbol}}
90 extern int b(); // expected-note {{previous}}
91 using T::b
; // expected-error {{different kind of symbol}}
94 using T::c
; // expected-note {{previous}}
95 using U::c
; // expected-error-re {{redefinition of 'c'{{$}}}}
99 template<typename T
, typename U
> void value_vs_type() {
100 using T::Xt
; // expected-note {{previous}}
101 typedef struct {} Xt
; // expected-error {{different kind of symbol}}
104 using T::Xs
; // expected-note {{hidden by}}
107 Xs xs
; // expected-error {{must use 'struct'}}
109 using T::Xe
; // expected-note {{hidden by}}
112 Xe xe
; // expected-error {{must use 'enum'}}
114 typedef struct {} Yt
; // expected-note {{candidate}}
115 using T::Yt
; // eypected-error {{different kind of symbol}} expected-note {{candidate}}
116 Yt yt
; // expected-error {{ambiguous}}
119 using T::Ys
; // expected-note {{hidden by}}
121 Ys ys
; // expected-error {{must use 'struct'}}
124 using T::Ye
; // expected-note {{hidden by}}
125 Ye ye
; // expected-error {{must use 'enum'}}
128 template<typename T
> void type() {
129 // Must be a class member because T:: can only name a class or enum,
130 // and an enum cannot have a type member.
131 using typename
T::X
; // expected-error {{cannot refer to class member}}
134 namespace N1
{ enum E
{ a
, b
, c
}; }
135 namespace N2
{ enum E
{ a
, b
, c
}; }
136 void g() { value_vs_value
<N1::E
, N2::E
>(); }
137 #if __cplusplus < 201103L
138 // expected-note@-2 {{in instantiation of}}
141 #if __cplusplus >= 201402L
142 namespace partial_substitute
{
143 template<typename T
> auto f() {
145 using A
= typename
T::template U
<decltype(x
)>;
149 using typename
A::type
;
150 type
f(int) { return e
; }
157 template<typename T
> struct U
{
165 return s
.f(0) + s
.f(0, 0);
168 template<typename T
, typename U
> auto g() {
170 using X
= decltype(x
);
171 struct S
: T::template Q
<X
>, U::template Q
<X
> {
172 using T::template Q
<X
>::f
;
173 using U::template Q
<X
>::f
;
175 void h(int n
) { f(n
); }
180 struct A
{ template<typename
> struct Q
{ int f(); }; };
181 struct B
{ template<typename
> struct Q
{ int f(int); }; };
183 auto s
= g
<A
, B
>()(0);
192 template<typename T
, typename U
> struct RepeatedMember
: T
, U
{
193 // FIXME: This is the wrong error: we should complain that a member type
194 // cannot be redeclared at class scope.
195 using typename
T::type
; // expected-note {{candidate}}
196 using typename
U::type
; // expected-note {{candidate}}
197 type x
; // expected-error {{ambiguous}}
210 using S::n
; // expected-error{{class member}} expected-note {{use a reference instead}}
211 #if __cplusplus < 201103L
212 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]]
214 // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:6}:"auto &n = "
217 using S::Q
; // expected-error{{class member}}
218 #if __cplusplus < 201103L
219 // expected-note@-2 {{use a typedef declaration instead}}
220 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
221 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" Q"
223 // expected-note@-6 {{use an alias declaration instead}}
224 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"Q = "
227 using S::E
; // expected-error{{class member}}
228 #if __cplusplus < 201103L
229 // expected-note@-2 {{use a typedef declaration instead}}
230 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
231 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" E"
233 // expected-note@-6 {{use an alias declaration instead}}
234 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"E = "
237 using S::T
; // expected-error{{class member}}
238 #if __cplusplus < 201103L
239 // expected-note@-2 {{use a typedef declaration instead}}
240 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
241 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" T"
243 // expected-note@-6 {{use an alias declaration instead}}
244 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"T = "
247 using S::f
; // expected-error{{class member}}
248 using S::g
; // expected-error{{class member}}
251 using S::n
; // expected-error{{class member}} expected-note {{use a reference instead}}
252 #if __cplusplus < 201103L
253 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]]
255 // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:8}:"auto &n = "
258 using S::Q
; // expected-error{{class member}}
259 #if __cplusplus < 201103L
260 // expected-note@-2 {{use a typedef declaration instead}}
261 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
262 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" Q"
264 // expected-note@-6 {{use an alias declaration instead}}
265 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"Q = "
268 using S::E
; // expected-error{{class member}}
269 #if __cplusplus < 201103L
270 // expected-note@-2 {{use a typedef declaration instead}}
271 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
272 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" E"
274 // expected-note@-6 {{use an alias declaration instead}}
275 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"E = "
278 using S::T
; // expected-error{{class member}}
279 #if __cplusplus < 201103L
280 // expected-note@-2 {{use a typedef declaration instead}}
281 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
282 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" T"
284 // expected-note@-6 {{use an alias declaration instead}}
285 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"T = "
288 using S::f
; // expected-error{{class member}}
289 using S::g
; // expected-error{{class member}}