1 // RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98-20,cxx20-23,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98-17,cxx98-20,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx98 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
8 #if __cplusplus == 199711L
9 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
10 // cxx98-error@-1 {{variadic macros are a C99 feature}}
13 #if __cplusplus == 199711L
14 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
16 #define __enable_constant_folding
19 namespace cwg300
{ // cwg300: yes
20 template<typename R
, typename A
> void f(R (&)(A
)) {}
25 namespace cwg301
{ // cwg301: 3.5
28 template<typename T
> void operator+(T
, T
);
32 bool a
= (void(*)(S
, S
))operator+<S
> < (void(*)(S
, S
))operator+<S
>;
33 // expected-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}}
34 bool b
= (void(*)(S
, S
))operator- < (void(*)(S
, S
))operator-;
35 // cxx98-17-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}}
36 // cxx20-23-error@-2 {{expected '>'}}
37 // cxx20-23-note@-3 {{to match this '<'}}
38 bool c
= (void(*)(S
, S
))operator+ < (void(*)(S
, S
))operator-;
39 // expected-error@-1 {{expected '>'}}
40 // expected-note@-2 {{to match this '<'}}
43 template<typename T
> void f() {
44 // FIXME: We are emitting a lot of bogus diagnostics here.
45 typename
T::template operator+<int> a
;
46 // expected-error@-1 {{typename specifier refers to a non-type template}}
47 // expected-error@-2 {{'template' keyword not permitted here}}
48 // expected-error@-3 {{a type specifier is required for all declarations}}
49 // expected-error@-4 {{'operator+' cannot be the name of a variable or data member}}
50 // expected-error@-5 {{expected ';' at end of declaration}}
51 // FIXME: This shouldn't say (null).
52 class T::template operator+<int> b
;
53 // expected-error@-1 {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
54 enum T::template operator+<int> c
;
55 // expected-error@-1 {{expected identifier}}
56 enum T::template operator+<int>::E d
;
57 // expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}}
58 // expected-error@-2 {{ISO C++ forbids forward references to 'enum' types}}
59 enum T::template X
<int>::E e
;
60 T::template operator+<int>::foobar();
61 // expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}}
62 T::template operator+<int>(0); // ok
65 // FIXME: We are emitting a bunch of bogus diagnostics for the next 3 lines.
66 // All of them do a bad job at explaining that 'class' is not allowed here.
67 template<typename T
> class operator&<T
*> {};
68 // expected-error@-1 {{declaration of anonymous class must be a definition}}
69 // expected-error@-2 {{declaration does not declare anything}}
70 template<typename T
> class T::operator& {};
71 // expected-error@-1 {{expected identifier}}
72 // expected-error@-2 {{declaration of anonymous class must be a definition}}
73 // expected-error@-3 {{declaration does not declare anything}}
74 template<typename T
> class S::operator&<T
*> {};
75 // expected-error@-1 {{expected identifier}}
76 // expected-error@-2 {{declaration of anonymous class must be a definition}}
77 // expected-error@-3 {{declaration does not declare anything}}
80 namespace cwg302
{ // cwg302: 3.0
81 struct A
{ A(); ~A(); };
82 #if __cplusplus < 201103L
84 // expected-error@-1 {{implicit default constructor for 'cwg302::B' must explicitly initialize the const member 'n'}}
85 // expected-note@#cwg302-b {{in implicit default constructor for 'cwg302::B' first required here}}
86 // expected-note@#cwg302-B-n {{declared here}}
87 const int n
; // #cwg302-B-n
89 } b
= B(); // #cwg302-b
90 // Trivial default constructor C::C() is not called here.
96 const int n
; // #cwg302-B-n
99 // expected-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
100 // expected-note@#cwg302-B-n {{default constructor of 'B' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
101 // C::C() is called here, because even though it's trivial, it's deleted.
103 const int n
; // #cwg302-C-n
105 // expected-error@-1 {{call to implicitly-deleted default constructor of 'C'}}
106 // expected-note@#cwg302-C-n {{default constructor of 'C' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
115 namespace cwg304
{ // cwg304: 2.9
118 // expected-error@-1 {{reference to type 'int' requires an initializer}}
120 struct S
{ int &b
; }; // #cwg304-S
121 // cxx98-error@-1 {{reference to type 'int' requires an initializer}}
122 // cxx98-note@#cwg304-m {{in value-initialization of type 'S' here}}
123 int m
= S().b
; // #cwg304-m
124 // since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'S'}}
125 // since-cxx11-note@#cwg304-S {{default constructor of 'S' is implicitly deleted because field 'b' of reference type 'int &' would not be initialized}}
128 namespace cwg305
{ // cwg305: no
143 struct B
{}; // #cwg305-h-B
145 // expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'B' (aka 'cwg305::A') of the object being destroyed}}
146 // expected-note@#cwg305-h-B {{type 'B' found by destructor name lookup}}
149 template<typename T
> struct X
{};
155 // expected-error@-1 {{no member named '~X' in 'cwg305::X<int>'}}
158 #if __cplusplus >= 201103L
160 template<typename T
> using T1
= Y
;
162 template<typename T
> using T2
= Y
;
168 template<typename T
> using T2
= T
;
172 // expected-error@-1 {{no member named 'T1' in 'cwg305::Z'}}
174 // expected-error@-1 {{no member named '~int' in 'cwg305::Z'}}
178 // FIXME: This is valid.
180 template<typename A
> struct R
{};
182 template<typename A
> using R
= Q::R
<int>;
183 void qr(Q::R
<int> x
) { x
.~R
<char>(); }
184 // expected-error@-1 {{no member named '~R' in 'cwg305::Q::R<int>'}}
188 namespace cwg306
{ // cwg306: dup 39
189 struct A
{ struct B
{}; };
190 struct C
{ typedef A::B B
; };
191 struct D
: A
, A::B
, C
{};
194 struct X
{}; // #cwg306-X
195 template<typename T
> struct Y
{ typedef T X
; }; // #cwg306-typedef-X
196 template<typename T
> struct Z
: X
, Y
<T
> {};
199 // expected-error@-1 {{member 'X' found in multiple base classes of different types}}
200 // expected-note@#cwg306-X {{member type 'cwg306::X' found}}
201 // expected-note@#cwg306-typedef-X {{member type 'const cwg306::X' found}}
206 namespace cwg308
{ // cwg308: 3.7
207 // This is mostly an ABI library issue.
213 // NB: the warning here is correct despite being the opposite of the
214 // comments in the catch handlers. The "unreachable" comment is correct
215 // because there is an ambiguous base path to A from the D that is thrown.
216 // The warnings generated are also correct because the handlers handle
217 // const B& and const A& and we don't check to see if other derived classes
218 // exist that would cause an ambiguous base path. We issue the diagnostic
219 // despite the potential for a false positive because users are not
220 // expected to have ambiguous base paths all that often, so the false
221 // positive rate should be acceptably low.
224 } catch (const A
&) { // #cwg308-catch-A
227 // expected-warning@-1 {{exception of type 'const B &' will be caught by earlier handler}}
228 // expected-note@#cwg308-catch-A {{for type 'const A &'}}
236 namespace cwg311
{ // cwg311: 3.0
237 namespace X
{ namespace Y
{} }
239 // cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}}
242 // cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}}
244 // FIXME: The diagnostics here are not very good.
245 namespace ::cwg311::X
{}
246 // expected-error@-1 {{expected identifier or '{'}}
247 // expected-warning@-2 {{extra qualification on member 'X'}}
248 // expected-error@-3 {{a type specifier is required for all declarations}}
249 // expected-error@-4 {{expected ';' after top level declarator}}
254 namespace cwg313
{ // cwg313: dup 299 c++11
255 struct A
{ operator int() const; };
256 // FIXME: should this be available in c++98 mode?
257 int *p
= new int[A()];
258 // cxx98-error@-1 {{implicit conversion from array size expression of type 'A' to integral type 'int' is a C++11 extension}}
261 namespace cwg314
{ // cwg314: no
263 template <typename T
> struct A
{
264 template <typename U
> struct B
{};
266 template <typename T
> struct C
: public A
<T
>::template B
<T
> {
267 C() : A
<T
>::template B
<T
>() {}
269 template <typename T
> struct C2
: public A
<T
>::B
<T
> {
270 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
271 C2() : A
<T
>::B
<T
>() {}
272 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
274 } // namespace cwg314
279 namespace cwg317
{ // cwg317: 3.5
280 void f() {} // #cwg317-f
282 // expected-error@-1 {{inline declaration of 'f' follows non-inline definition}}
283 // expected-note@#cwg317-f {{previous definition is here}}
287 inline int g() { return 0; }
291 int h() { return 0; } // #cwg317-h
293 // expected-error@-1 {{inline declaration of 'h' follows non-inline definition}}
294 // expected-note@#cwg317-h {{previous definition is here}}
297 namespace cwg318
{ // cwg318: sup 1310
302 namespace cwg319
{ // cwg319: no
304 // FIXME: We don't have a diagnostic for a name with linkage
305 // having a type without linkage.
309 extern "C" void f(ps
);
310 void g(ps
); // FIXME: ill-formed, type 'ps' has no linkage
312 static enum { e
} a1
;
313 enum { e2
} a2
; // FIXME: ill-formed, enum type has no linkage
316 typedef int (*pa
)[n1
];
317 pa parr
; // ok, type has linkage despite using 'n1'
319 template<typename
> struct X
{};
323 extern A a
; // FIXME: ill-formed
325 // cxx98-error@-1 {{template argument uses local type 'A'}}
328 extern B b
; // FIXME: ill-formed
330 // cxx98-error@-1 {{template argument uses local type 'A'}}
339 namespace cwg320
{ // cwg320: yes
340 #if __cplusplus >= 201103L
343 constexpr X(const X
&x
) : copies(x
.copies
+ 1) {}
346 constexpr X
f(X x
) { return x
; }
347 constexpr unsigned g(X x
) { return x
.copies
; }
348 static_assert(f(X()).copies
== g(X()) + 1, "expected one extra copy for return value");
352 namespace cwg321
{ // cwg321: dup 557
354 template<int> struct A
{
355 template<int> struct B
;
357 template<> template<> struct A
<0>::B
<0>;
360 template<> template<> struct N::A
<0>::B
<0> {};
362 template<typename T
> void g(T t
) { f(t
); }
363 template void g(N::A
<0>::B
<0>);
366 template<typename
> struct I
{ friend bool operator==(const I
&, const I
&); };
372 namespace cwg322
{ // cwg322: 2.8
374 template<typename T
> operator T
&();
376 int &r
= static_cast<int&>(a
);
382 namespace cwg324
{ // cwg324: 3.6
383 struct S
{ int n
: 1; } s
; // #cwg324-n
385 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
386 // expected-note@#cwg324-n {{bit-field is declared here}}
388 // expected-error@-1 {{address of bit-field requested}}
390 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
391 // expected-note@#cwg324-n {{bit-field is declared here}}
393 // expected-error@-1 {{address of bit-field requested}}
394 // FIXME: why don't we emit a note here, as for the rest of this type of diagnostic in this test?
395 int &e
= true ? s
.n
: s
.n
;
396 // expected-error@-1 {{non-const reference cannot bind to bit-field}}
397 int *f
= &(true ? s
.n
: s
.n
);
398 // expected-error@-1 {{address of bit-field requested}}
399 int &g
= (void(), s
.n
);
400 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
401 // expected-note@#cwg324-n {{bit-field is declared here}}
402 int *h
= &(void(), s
.n
);
403 // expected-error@-1 {{address of bit-field requested}}
405 // expected-error@-1 {{address of bit-field requested}}
408 namespace cwg326
{ // cwg326: 3.1
410 static_assert(__is_trivially_constructible(S
, const S
&), "");
413 namespace cwg327
{ // cwg327: dup 538
421 namespace cwg328
{ // cwg328: yes
422 struct A
; // #cwg328-A
424 // expected-error@-1 {{field has incomplete type 'A'}}
425 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
426 template<typename
> struct C
{ A a
; };
427 // expected-error@-1 {{field has incomplete type 'A'}}
428 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
430 // expected-error@-1 {{allocation of incomplete type 'A'}}
431 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
434 namespace cwg329
{ // cwg329: 3.5
436 template<typename T
> struct A
: B
{
437 friend void f(A a
) { g(a
); }
438 friend void h(A a
) { g(a
); }
439 // expected-error@-1 {{use of undeclared identifier 'g'}}
440 // expected-note@#cwg329-h-call {{in instantiation of member function 'cwg329::h' requested here}}
441 friend void i(B b
) {} // #cwg329-i
442 // expected-error@-1 {{redefinition of 'i'}}
443 // expected-note@#cwg329-b {{in instantiation of template class 'cwg329::A<char>' requested here}}
444 // expected-note@#cwg329-i {{previous definition is here}}
447 A
<char> b
; // #cwg329-b
450 h(a
); // #cwg329-h-call
454 namespace cwg330
{ // cwg330: 7
455 // Conversions between P and Q will be allowed by P0388.
456 typedef int *(*P
)[3];
457 typedef const int *const (*Q
)[3];
458 typedef const int *Qinner
[3];
459 typedef Qinner
const *Q2
; // same as Q, but 'const' written outside the array type
460 typedef const int *const (*R
)[4];
461 typedef const int *const (*S
)[];
462 typedef const int *(*T
)[];
463 void f(P p
, Q q
, Q2 q2
, R r
, S s
, T t
) {
467 // expected-error@-1 {{incompatible pointer types assigning to 'R' (aka 'const int *const (*)[4]') from 'P' (aka 'int *(*)[3]')}}
469 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'P' (aka 'int *(*)[3]')}} (fixed by p0388)
471 // expected-error@-1 {{incompatible pointer types assigning to 'T' (aka 'const int *(*)[]') from 'P' (aka 'int *(*)[3]')}}
473 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q' (aka 'const int *const (*)[3]')}} (fixed by p0388)
475 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q2' (aka 'const int *const (*)[3]')}} (fixed by p0388)
476 s
= t
; // ok, adding const
478 // expected-error@-1 {{assigning to 'T' (aka 'const int *(*)[]') from 'S' (aka 'const int *const (*)[]') discards qualifiers}}
479 (void) const_cast<P
>(q
);
480 (void) const_cast<P
>(q2
);
481 (void) const_cast<Q
>(p
);
482 (void) const_cast<Q2
>(p
);
483 (void) const_cast<S
>(p
);
484 // expected-error@-1 {{const_cast from 'P' (aka 'int *(*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}} (for now)
485 (void) const_cast<P
>(s
);
486 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') is not allowed}} (for now)
487 (void) const_cast<S
>(q
);
488 // expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}}
489 (void) const_cast<S
>(q2
);
490 // expected-error@-1 {{const_cast from 'Q2' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}}
491 (void) const_cast<Q
>(s
);
492 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}}
493 (void) const_cast<Q2
>(s
);
494 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q2' (aka 'const int *const (*)[3]') is not allowed}}
495 (void) const_cast<T
>(s
);
496 (void) const_cast<S
>(t
);
497 (void) const_cast<T
>(q
);
498 // expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') is not allowed}}
499 (void) const_cast<Q
>(t
);
500 // expected-error@-1 {{const_cast from 'T' (aka 'const int *(*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}}
502 (void) reinterpret_cast<P
>(q
);
503 // expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
504 (void) reinterpret_cast<P
>(q2
);
505 // expected-error@-1 {{reinterpret_cast from 'Q2' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
506 (void) reinterpret_cast<Q
>(p
);
507 (void) reinterpret_cast<Q2
>(p
);
508 (void) reinterpret_cast<S
>(p
);
509 (void) reinterpret_cast<P
>(s
);
510 // expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
511 (void) reinterpret_cast<S
>(q
);
512 (void) reinterpret_cast<S
>(q2
);
513 (void) reinterpret_cast<Q
>(s
);
514 (void) reinterpret_cast<Q2
>(s
);
515 (void) reinterpret_cast<T
>(s
);
516 // expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}}
517 (void) reinterpret_cast<S
>(t
);
518 (void) reinterpret_cast<T
>(q
);
519 // expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}}
520 (void) reinterpret_cast<Q
>(t
);
523 namespace swift_17882
{
524 typedef const char P
[72];
526 void f(P
&pr
, P
*pp
) {
527 (void) reinterpret_cast<const Q
&>(pr
);
528 (void) reinterpret_cast<const Q
*>(pp
);
532 typedef const volatile int A
[1][2][3];
533 typedef int *const X::*volatile *B1
;
534 typedef int *const X::* *B2
;
535 typedef int *X::* volatile *B3
;
536 typedef volatile int *(*const B4
)[4];
538 (void) reinterpret_cast<B1
*>(a
);
539 (void) reinterpret_cast<B2
*>(a
);
540 // expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B2 *' (aka 'int *const cwg330::swift_17882::X::***') because it casts away qualifiers, even though the source and destination types are unrelated}}
541 (void) reinterpret_cast<B3
*>(a
);
542 // expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B3 *' (aka 'int *cwg330::swift_17882::X::*volatile **') because it casts away qualifiers, even though the source and destination types are unrelated}}
543 (void) reinterpret_cast<B4
*>(a
);
548 namespace cwg331
{ // cwg331: 11
550 A(volatile A
&); // #cwg331-A-ctor
553 // expected-error@-1 {{no matching constructor for initialization of 'const A'}}
554 // expected-note@#cwg331-A-ctor {{candidate constructor not viable: requires 1 argument, but 0 were provided}}
556 // expected-error@-1 {{no matching constructor for initialization of 'const A'}}
557 // expected-note@#cwg331-A-ctor {{candidate constructor not viable: 1st argument ('const A') would lose const qualifier}}
560 namespace cwg332
{ // cwg332: dup 577
561 void f(volatile void);
562 // expected-error@-1 {{'void' as parameter must not have type qualifiers}}
563 // cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}}
565 // expected-error@-1 {{'void' as parameter must not have type qualifiers}}
566 void h(int n
, volatile void);
567 // expected-error@-1 {{'void' must be the first and only parameter if specified}}
568 // cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}}
571 namespace cwg333
{ // cwg333: yes
578 namespace cwg334
{ // cwg334: yes
579 template<typename T
> void f() {
584 friend S
operator,(S
, int);
587 template void f
<S
>();
592 namespace cwg336
{ // cwg336: yes
594 template<class T1
> class A
{
595 template<class T2
> class B
{
596 template<class T3
> void mf1(T3
);
600 template<> template<class X
> class A
<int>::B
{}; // #cwg336-B
601 template<> template<> template<class T
> void A
<int>::B
<double>::mf1(T t
) {}
602 // expected-error@-1 {{out-of-line definition of 'mf1' does not match any declaration in 'cwg336::Pre::A<int>::B<double>'}}
603 // expected-note@#cwg336-B {{defined here}}
604 template<class Y
> template<> void A
<Y
>::B
<double>::mf2() {}
605 // expected-error@-1 {{nested name specifier 'A<Y>::B<double>::' for declaration does not refer into a class, class template or class template partial specialization}}
608 template<class T1
> class A
{
609 template<class T2
> class B
{
610 template<class T3
> void mf1(T3
);
614 template<> template<class X
> class A
<int>::B
{
615 template<class T
> void mf1(T
);
617 template<> template<> template<class T
> void A
<int>::B
<double>::mf1(T t
) {}
618 // FIXME: This diagnostic isn't very good.
619 template<class Y
> template<> void A
<Y
>::B
<double>::mf2() {}
620 // expected-error@-1 {{nested name specifier 'A<Y>::B<double>::' for declaration does not refer into a class, class template or class template partial specialization}}
624 namespace cwg337
{ // cwg337: yes
625 template<typename T
> void f(T (*)[1]);
626 template<typename T
> int &f(...);
628 struct A
{ virtual ~A() = 0; };
631 // FIXME: The language rules here are completely broken. We cannot determine
632 // whether an incomplete type is abstract. See CWG1640, which will probably
633 // supersede this one and remove this rule.
636 // expected-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'void'}}
637 struct B
{ virtual ~B() = 0; };
642 namespace cwg339
{ // cwg339: 2.8
643 template <int I
> struct A
{ static const int value
= I
; };
646 char (&xxx(float))[2];
648 template<class T
> A
<sizeof(xxx((T
)0))> f(T
) {} // #cwg339-f
654 // expected-error@-1 {{no matching function}}
655 // expected-note@#cwg339-f {{candidate}}
662 template <class T
> struct conv_int
{
663 static const bool value
= sizeof(f(T())) == 1;
666 template <class T
> bool conv_int2(A
<sizeof(f(T()))> p
);
668 template<typename T
> A
<sizeof(f(T()))> make_A();
670 static_assert(conv_int
<char>::value
, "");
671 bool b
= conv_int2
<char>(A
<1>());
672 A
<1> c
= make_A
<char>();
675 namespace cwg340
{ // cwg340: yes
676 struct A
{ A(int); };
677 struct B
{ B(A
, A
, int); };
682 namespace cwg341
{ // cwg341: sup 1708
685 extern "C" int &cwg341_a
= n
; // #cwg341_a
688 extern "C" int &cwg341_a
= cwg341_a
;
689 // expected-error@-1 {{redefinition of 'cwg341_a'}}
690 // expected-note@#cwg341_a {{previous definition is here}}
692 extern "C" void cwg341_b(); // #cwg341_b
695 // expected-error@-1 {{declaration of 'cwg341_a' in global scope conflicts with declaration with C language linkage}}
696 // expected-note@#cwg341_a {{declared with C language linkage here}}
698 // expected-error@-1 {{declaration of 'cwg341_b' in global scope conflicts with declaration with C language linkage}}
699 // expected-note@#cwg341_b {{declared with C language linkage here}}
700 int cwg341_c
; // #cwg341_c
701 int cwg341_d
; // #cwg341_d
703 extern "C" int cwg341_c
;
704 // expected-error@-1 {{declaration of 'cwg341_c' with C language linkage conflicts with declaration in global scope}}
705 // expected-note@#cwg341_c {{declared in global scope here}}
706 extern "C" void cwg341_d();
707 // expected-error@-1 {{declaration of 'cwg341_d' with C language linkage conflicts with declaration in global scope}}
708 // expected-note@#cwg341_d {{declared in global scope here}}
710 namespace A
{ extern "C" int cwg341_e
; } // #cwg341_e
711 namespace B
{ extern "C" void cwg341_e(); }
712 // expected-error@-1 {{redefinition of 'cwg341_e' as different kind of symbol}}
713 // expected-note@#cwg341_e {{previous definition is here}}
718 namespace cwg343
{ // cwg343: no
720 template<typename T
> struct A
{
721 template<typename U
> struct B
{};
723 // FIXME: In these contexts, the 'template' keyword is optional.
724 template<typename T
> struct C
: public A
<T
>::B
<T
> {
725 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
726 C() : A
<T
>::B
<T
>() {}
727 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
731 namespace cwg344
{ // cwg344: dup 1435
732 struct A
{ inline virtual ~A(); };
733 struct B
{ friend A::~A(); };
736 namespace cwg345
{ // cwg345: yes
739 int X
; // #cwg345-int-X
744 template <class T
> void f(T t
) { typename
T::X x
; }
745 // expected-error@-1 {{typename specifier refers to non-type member 'X' in 'cwg345::A'}}
746 // expected-note@#cwg345-f-a {{in instantiation of function template specialization 'cwg345::f<cwg345::A>' requested here}}
747 // expected-note@#cwg345-int-X {{referenced member 'X' is declared here}}
756 namespace cwg347
{ // cwg347: yes
764 struct derived
: base
{}; // #cwg347-derived
766 struct derived::nested
{};
767 // expected-error@-1 {{no struct named 'nested' in 'cwg347::derived'}}
769 // expected-error@-1 {{no member named 'n' in 'cwg347::derived'}}
771 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg347::derived'}}
772 // expected-note@#cwg347-derived {{defined here}}
774 // expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in 'cwg347::derived'}}
775 // expected-note@#cwg347-derived {{defined here}}
780 namespace cwg349
{ // cwg349: no
782 template <class T
> operator T
***() {
785 // cxx98-20-error@-1 {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
786 // since-cxx23-error@-2 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
787 // expected-note@#cwg349-p1 {{in instantiation of function template specialization 'cwg349::A::operator const int ***<const int>' requested here}}
791 // FIXME: This is valid.
793 const int *const *const *p1
= a
; // #cwg349-p1
796 template <class T
> operator T
***() {
802 // FIXME: This is invalid.
804 const int *const *const *p2
= b
;
809 namespace cwg352
{ // cwg352: 2.8
813 template<typename R
, typename A
> void foo(E
, R (*)(A
)); // #cwg352-foo
816 template<typename T
> void arg(T
);
817 template<typename T
> int arg(T
) = delete; // #cwg352-deleted
818 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
822 // expected-error@-1 {{no matching function for call to 'foo'}}
823 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
826 foo
<int, int>(e
, &arg
);
827 // expected-error@-1 {{attempt to use a deleted function}}
828 // expected-note@#cwg352-deleted {{'arg<int>' has been explicitly marked deleted here}}
835 // expected-error@-1 {{no matching function for call to 'foo'}}
836 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
839 foo
<int, int>(e
, &arg
); // ok, uses non-template
844 template<int I
> void f1(int (&)[I
]);
845 template<int I
> void f2(int (&)[I
+1]); // #cwg352-f2
846 template<int I
> void f3(int (&)[I
+1], int (&)[I
]);
852 // expected-error@-1 {{no matching function for call to 'f2'}}
853 // expected-note@#cwg352-f2 {{candidate template ignored: couldn't infer template argument 'I'}}
857 template<int I
> struct S
{};
858 template<int I
> void g1(S
<I
>);
859 template<int I
> void g2(S
<I
+1>); // #cwg352-g2
860 template<int I
> void g3(S
<I
+1>, S
<I
>);
866 // expected-error@-1 {{no matching function for call to 'g2'}}
867 // expected-note@#cwg352-g2 {{candidate template ignored: couldn't infer template argument 'I'}}
871 template<typename T
> void h1(T
= 0); // #cwg352-h1
872 template<typename T
> void h2(T
, T
= 0);
875 // expected-error@-1 {{no matching function for call to 'h1'}}
876 // expected-note@#cwg352-h1 {{candidate template ignored: couldn't infer template argument 'T'}}
882 template<typename T
> int tmpl(T
);
883 template<typename R
, typename A
> void i1(R (*)(A
)); // #cwg352-i1
884 template<typename R
, typename A
> void i2(R
, A
, R (*)(A
)); // #cwg352-i2
886 extern int single(int);
890 extern int ambig(float), ambig(int);
892 // expected-error@-1 {{no matching function for call to 'i1'}}
893 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
896 extern void no_match(float), no_match(int);
898 // expected-error@-1 {{no matching function for call to 'i1'}}
899 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
901 // expected-error@-1 {{no matching function for call to 'i2'}}
902 // expected-note@#cwg352-i2 {{candidate function [with R = int, A = int] not viable: no overload of 'no_match' matching 'int (*)(int)' for 3rd argument}}
905 // expected-error@-1 {{no matching function for call to 'i1'}}
906 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
911 template<typename T
> struct is_int
;
912 template<> struct is_int
<int> {};
915 template<typename T
> int f(T (*p
)(T
)) { is_int
<T
>(); }
922 template<typename T
> int f(T
, T (*p
)(T
)) { is_int
<T
>(); }
929 template <class T
> int f(T
, T (*p
)(T
)) { is_int
<T
>(); }
931 template <class T
> T
g(T
);
936 template<int I
> class A
{};
937 template<int I
> void g(A
<I
+1>); // #cwg352-g
938 template<int I
> void f(A
<I
>, A
<I
+1>);
939 void h(A
<1> a1
, A
<2> a2
) {
941 // expected-error@-1 {{no matching function for call to 'g'}}
942 // expected-note@#cwg352-g {{candidate template ignored: couldn't infer template argument 'I'}}
949 // cwg353 needs an IRGen test.
951 namespace cwg354
{ // cwg354: yes c++11
952 // FIXME: Should we allow this in C++98 too?
955 template<int*> struct ptr
{}; // #cwg354-ptr
956 ptr
<0> p0
; // #cwg354-p0
957 // cxx98-error@#cwg354-p0 {{non-type template argument does not refer to any declaration}}
958 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
959 // cxx11-14-error@#cwg354-p0 {{null non-type template argument must be cast to template parameter type 'int *'}}
960 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
961 // since-cxx17-error@#cwg354-p0 {{conversion from 'int' to 'int *' is not allowed in a converted constant expression}}
963 // cxx98-error@-1 {{non-type template argument does not refer to any declaration}}
964 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
965 ptr
<(float*)0> p2
; // #cwg354-p2
966 // cxx98-error@#cwg354-p2 {{non-type template argument does not refer to any declaration}}
967 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
968 // cxx11-14-error@#cwg354-p2 {{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
969 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
970 // since-cxx17-error@#cwg354-p2 {{value of type 'float *' is not implicitly convertible to 'int *'}}
971 ptr
<(int S::*)0> p3
; // #cwg354-p3
972 // cxx98-error@#cwg354-p3 {{non-type template argument does not refer to any declaration}}
973 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
974 // cxx11-14-error@#cwg354-p3 {{null non-type template argument of type 'int cwg354::S::*' does not match template parameter of type 'int *'}}
975 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
976 // since-cxx17-error@#cwg354-p3 {{value of type 'int cwg354::S::*' is not implicitly convertible to 'int *'}}
978 template<int*> int both(); // #cwg354-both-int-ptr
979 template<int> int both(); // #cwg354-both-int
981 int b1
= both
<(int*)0>();
982 // cxx98-error@-1 {{no matching function for call to 'both'}}
983 // cxx98-note@#cwg354-both-int-ptr {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
984 // cxx98-note@#cwg354-both-int {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
986 template<int S::*> struct ptr_mem
{}; // #cwg354-ptr_mem
987 ptr_mem
<0> m0
; // #cwg354-m0
988 // cxx98-error@#cwg354-m0 {{non-type template argument of type 'int' cannot be converted to a value of type 'int cwg354::S::*'}}
989 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
990 // cxx11-14-error@#cwg354-m0 {{null non-type template argument must be cast to template parameter type 'int cwg354::S::*'}}
991 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
992 // since-cxx17-error@#cwg354-m0 {{conversion from 'int' to 'int cwg354::S::*' is not allowed in a converted constant expression}}
993 ptr_mem
<(int S::*)0> m1
;
994 // cxx98-error@-1 {{non-type template argument is not a pointer to member constant}}
995 ptr_mem
<(float S::*)0> m2
; // #cwg354-m2
996 // cxx98-error@#cwg354-m2 {{non-type template argument of type 'float cwg354::S::*' cannot be converted to a value of type 'int cwg354::S::*'}}
997 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
998 // cxx11-14-error@#cwg354-m2 {{null non-type template argument of type 'float cwg354::S::*' does not match template parameter of type 'int cwg354::S::*'}}
999 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
1000 // since-cxx17-error@#cwg354-m2 {{value of type 'float cwg354::S::*' is not implicitly convertible to 'int cwg354::S::*'}}
1001 ptr_mem
<(int *)0> m3
; // #cwg354-m3
1002 // cxx98-error@#cwg354-m3 {{non-type template argument of type 'int *' cannot be converted to a value of type 'int cwg354::S::*'}}
1003 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
1004 // cxx11-14-error@#cwg354-m3 {{null non-type template argument of type 'int *' does not match template parameter of type 'int cwg354::S::*'}}
1005 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
1006 // since-cxx17-error@#cwg354-m3 {{value of type 'int *' is not implicitly convertible to 'int cwg354::S::*'}}
1009 struct cwg355_S
; // cwg355: yes
1010 struct ::cwg355_S
{};
1011 // expected-warning@-1 {{extra qualification on member 'cwg355_S'}}
1012 namespace cwg355
{ struct ::cwg355_S s
; }
1016 namespace cwg357
{ // cwg357: yes
1017 template<typename T
> struct A
{ // #cwg357-A
1018 void f() const; // #cwg357-f
1020 template<typename T
> void A
<T
>::f() {}
1021 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'A<T>'}}
1022 // expected-note@#cwg357-A {{defined here}}
1023 // expected-note@#cwg357-f {{member declaration does not match because it is const qualified}}
1025 struct B
{ // #cwg357-B
1026 template<typename T
> void f();
1028 template<typename T
> void B::f() const {}
1029 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg357::B'}}
1030 // expected-note@#cwg357-B {{defined here}}
1033 namespace cwg358
{ // cwg358: yes
1034 extern "C" void cwg358_f();
1037 extern "C" void cwg358_f() { var
= 10; }
1041 namespace cwg359
{ // cwg359: yes
1042 // Note, the example in the DR is wrong; it doesn't contain an anonymous
1053 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1058 // expected-error@-1 {{types cannot be declared in an anonymous union}}
1063 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1070 namespace cwg360
{ // cwg360: yes
1081 using A::foo
; // #cwg360-using-foo
1083 using A::bar
; // #cwg360-using-bar
1089 int foo
= B().foo();
1090 // expected-error@-1 {{'foo' is a private member of 'cwg360::B'}}
1091 // expected-note@#cwg360-using-foo {{declared private here}}
1092 int bar
= B().bar();
1093 // expected-error@-1 {{'bar' is a protected member of 'cwg360::B'}}
1094 // expected-note@#cwg360-using-bar {{declared protected here}}
1095 int baz
= B().baz();
1097 } // namespace cwg360
1102 namespace cwg364
{ // cwg364: yes
1110 // expected-error@-1 {{call to non-static member function without an object argument}}
1116 #if "foo" // expected-error {{invalid token at start of a preprocessor expression}}
1119 namespace cwg367
{ // cwg367: yes
1120 static_assert(__enable_constant_folding(true ? throw 0 : 4), "");
1121 // expected-error@-1 {{expression is not an integral constant expression}}
1122 static_assert(__enable_constant_folding(true ? 4 : throw 0), "");
1123 static_assert(__enable_constant_folding(true ? *new int : 4), "");
1124 // expected-error@-1 {{expression is not an integral constant expression}}
1125 // expected-note@-2 {{read of uninitialized object is not allowed in a constant expression}}
1126 static_assert(__enable_constant_folding(true ? 4 : *new int), "");
1130 namespace cwg368
{ // cwg368: 3.6
1131 template<typename T
, T
> struct S
{}; // #cwg368-S
1132 template<typename T
> int f(S
<T
, T()> *);
1133 // expected-error@-1 {{template argument for non-type template parameter is treated as function type 'T ()'}}
1134 // expected-note@#cwg368-S {{template parameter is declared here}}
1135 template<typename T
> int g(S
<T
, (T())> *); // #cwg368-g
1136 template<typename T
> int g(S
<T
, true ? T() : T()> *); // #cwg368-g-2
1138 int n
= g
<X
>(0); // #cwg368-g-call
1139 // cxx98-17-error@#cwg368-g-call {{no matching function for call to 'g'}}
1140 // cxx98-17-note@#cwg368-g {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}}
1141 // cxx98-17-note@#cwg368-g-2 {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}}
1142 // cxx20-23-error@#cwg368-g-call {{call to 'g' is ambiguous}}
1143 // cxx20-23-note@#cwg368-g {{candidate function [with T = cwg368::X]}}
1144 // cxx20-23-note@#cwg368-g-2 {{candidate function [with T = cwg368::X]}}
1149 namespace cwg372
{ // cwg372: no
1150 namespace example1
{
1151 template<typename T
> struct X
{
1153 typedef T Type
; // #cwg372-ex1-Type
1155 template<typename T
> struct Y
{};
1157 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
1158 // the protected member T1<T>::Type.
1159 template<typename T
,
1160 template<typename
> class T1
,
1161 template<typename
> class T2
> struct Z1
:
1163 T2
<typename T1
<T
>::Type
> {};
1164 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1165 // expected-note@#cwg372-z1 {{in instantiation of template class 'cwg372::example1::Z1<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1166 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1168 template<typename T
,
1169 template<typename
> class T1
,
1170 template<typename
> class T2
> struct Z2
:
1171 T2
<typename T1
<T
>::Type
>,
1172 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1173 // expected-note@#cwg372-z2 {{in instantiation of template class 'cwg372::example1::Z2<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1174 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1177 Z1
<int, X
, Y
> z1
; // #cwg372-z1
1178 Z2
<int, X
, Y
> z2
; // #cwg372-z2
1181 namespace example2
{
1184 typedef int Type
; // #cwg372-ex2-Type
1186 template<typename T
> struct A
{
1188 // expected-error@-1 {{'Type' is a private member of 'cwg372::example2::X'}}
1189 // expected-note@#cwg372-ax {{in instantiation of template class 'cwg372::example2::A<cwg372::example2::X>' requested here}}
1190 // expected-note@#cwg372-ex2-Type {{declared private here}}
1192 A
<X
> ax
; // #cwg372-ax
1195 namespace example3
{
1198 typedef int N
; // #cwg372-N
1201 template<typename T
> struct B
{};
1202 template<typename U
> struct C
: U
, B
<typename
U::N
> {};
1203 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1204 // expected-note@#cwg372-x {{in instantiation of template class 'cwg372::example3::C<cwg372::example3::A>' requested here}}
1205 // expected-note@#cwg372-N {{declared protected here}}
1206 template<typename U
> struct D
: B
<typename
U::N
>, U
{};
1207 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1208 // expected-note@#cwg372-y {{in instantiation of template class 'cwg372::example3::D<cwg372::example3::A>' requested here}}
1209 // expected-note@#cwg372-N {{declared protected here}}
1211 C
<A
> x
; // #cwg372-x
1212 D
<A
> y
; // #cwg372-y
1215 namespace example4
{
1229 // FIXME: This is valid: deriving from A gives D access to A::B
1230 namespace std_example
{
1233 struct B
{}; // #cwg372-B-std
1235 struct D
: A::B
, A
{};
1236 // expected-error@-1 {{'B' is a protected member of 'cwg372::std_example::A'}}
1237 // expected-note@#cwg372-B-std {{declared protected here}}
1240 // FIXME: This is valid: deriving from A::B gives access to A::B!
1244 struct B
; // #cwg372-B
1248 // expected-error@-1 {{'B' is a protected member of 'cwg372::badwolf::A'}}
1249 // expected-note@#cwg372-B {{declared protected here}}
1253 namespace cwg373
{ // cwg373: 5
1254 namespace X
{ int cwg373
; }
1255 struct cwg373
{ // #cwg373-struct
1257 using namespace cwg373::X
;
1259 // expected-error@-1 {{'cwg373' does not refer to a value}}
1260 // expected-note@#cwg373-struct {{declared here}}
1261 namespace Y
= cwg373::X
;
1266 struct A
{ struct B
{}; }; // #cwg373-A
1268 // expected-error@-1 {{expected namespace name}}
1269 // expected-note@#cwg373-A {{'A' declared here}}
1270 using namespace A::B
;
1271 // expected-error@-1 {{expected namespace name}}
1272 // expected-note@#cwg373-A {{'A' declared here}}
1275 namespace cwg374
{ // cwg374: 7
1278 template<typename T
> void f();
1279 template<typename T
> struct A
{ void f(); };
1281 template<> void N::f
<char>() {}
1282 template<> void N::A
<char>::f() {}
1283 template<> struct N::A
<int> {};
1289 namespace cwg377
{ // cwg377: yes
1291 // expected-error@-1 {{enumeration values exceed range of largest integer}}
1292 a
= -__LONG_LONG_MAX__
- 1,
1293 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1294 b
= 2 * (unsigned long long)__LONG_LONG_MAX__
1295 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1296 // cxx98-error@-2 {{'long long' is a C++11 extension}}
1303 namespace cwg381
{ // cwg381: yes
1307 struct B
: virtual A
{};
1310 struct E
: public C
, public D
{};
1311 struct F
: public A
{};
1315 /* expected-error@-1 {{ambiguous conversion from derived class 'E' to base class 'cwg381::B':
1316 struct cwg381::E -> C -> B
1317 struct cwg381::E -> D -> B}} */
1323 namespace cwg382
{ // cwg382: yes c++11
1324 // FIXME: Should we allow this in C++98 mode?
1325 struct A
{ typedef int T
; };
1327 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1328 typename
cwg382::A a
;
1329 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1331 // expected-error@-1 {{expected a qualified name after 'typename'}}
1334 namespace cwg383
{ // cwg383: yes
1335 struct A
{ A
&operator=(const A
&); };
1337 union C
{ C
&operator=(const C
&); };
1339 static_assert(!__is_pod(A
) && !__is_pod(B
) && !__is_pod(C
) && !__is_pod(D
), "");
1342 namespace cwg384
{ // cwg384: yes
1344 template<typename T
> struct Base
{};
1345 template<typename T
> struct X
{
1346 struct Y
: public Base
<T
> {
1347 Y
operator+(int) const;
1349 Y
f(unsigned i
) { return Y() + i
; }
1355 template<typename T
> int *operator+(T
, unsigned);
1364 namespace cwg385
{ // cwg385: 2.8
1365 struct A
{ protected: void f(); };
1366 struct B
: A
{ using A::f
; };
1367 struct C
: A
{ void g(B b
) { b
.f(); } };
1368 void h(B b
) { b
.f(); }
1370 struct D
{ int n
; }; // #cwg385-n
1371 struct E
: protected D
{}; // #cwg385-E
1372 struct F
: E
{ friend int i(E
); };
1373 int i(E e
) { return e
.n
; }
1374 // expected-error@-1 {{'n' is a protected member of 'cwg385::D'}}
1375 // expected-note@#cwg385-E {{constrained by protected inheritance here}}
1376 // expected-note@#cwg385-n {{member is declared here}}
1379 namespace cwg386
{ // cwg386: no
1380 namespace example1
{
1382 // Binds name 'f' in N1. Target scope is N1.
1383 template<typename T
> void f( T
* x
) {
1384 // ... other stuff ...
1390 // Bind name 'f' in N2. When a single search find this declaration,
1391 // it's replaced with N1::f declaration.
1394 // According to _N4988_.[dcl.meaning]/3.3:
1395 // `f<int>` is not a qualified-id, so its target scope is N2.
1396 // `f<int>` is a template-id, so 'f' undergoes (unqualified) lookup.
1397 // Search performed by unqualified lookup finds N1::f via using-declaration,
1398 // but this result is not considered, because it's not nominable in N2,
1399 // which is because its target scope is N1.
1400 // So unqualified lookup doesn't find anything, making this declaration ill-formed.
1401 template<> void f
<int>( int* );
1402 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1406 // According to _N4988_.[dcl.meaning]/2.2:
1407 // `f<>` is a template-id and not a template declaration,
1408 // so its terminal name 'f' undergoes (unqualified) lookup.
1409 // Search in N2 performed by unqualified lookup finds
1410 // (single) N1::f declaration via using-declaration.
1411 // N1::f is replaced with N1::f<> specialization after deduction,
1412 // and this is the result of the unqualified lookup.
1413 // This friend declaration correspond to the result of the lookup.
1414 // All lookup results target the same scope, which is N1,
1415 // so target scope of this friend declaration is also N1.
1416 // FIXME: This is well-formed.
1417 friend void f
<>( Test
* x
);
1418 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1421 } // namespace example1
1423 namespace example2
{
1425 // Binds name 'f' in N1. Target scope is N1.
1426 void f(); // #cwg386-ex2-N1-f
1430 // Bind name 'f' in N2. When a single search finds this declaration,
1431 // it's replaced with N1::f declaration.
1432 using N1::f
; // #cwg386-ex2-using
1434 // According to _N4988_.[dcl.meaning]/2.2:
1435 // `N2::f` is a qualified-id, so its terminal name 'f' undergoes (qualified) lookup.
1436 // Search in N2 performed by qualified lookup finds N1::f via using-declaration,
1437 // which is the (only) result of qualified lookup.
1438 // This friend declaration corresponds to the result of the lookup.
1439 // All lookup results target the same scope, which is N1,
1440 // so target scope of this friend declaration is also N1.
1441 // FIXME: This is well-formed.
1442 friend void N2::f();
1443 // expected-error@-1 {{cannot befriend target of using declaration}}
1444 // expected-note@#cwg386-ex2-N1-f {{target of using declaration}}
1445 // expected-note@#cwg386-ex2-using {{using declaration}}
1448 } // namespace example2
1449 } // namespace cwg386
1451 namespace cwg387
{ // cwg387: 2.8
1453 template<typename T
> class number
{
1454 number(int); // #cwg387-number-ctor
1455 friend number
gcd(number
&x
, number
&y
) {}
1459 number
<double> a(3);
1460 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1461 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1462 number
<double> b(4);
1463 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1464 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1467 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1472 template <typename T
> class number
{
1475 friend number
gcd(number x
, number y
) { return 0; }
1479 number
<double> a(3), b(4);
1482 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1487 // FIXME: cwg388 needs libc++abi test
1489 namespace cwg389
{ // cwg389: no
1491 typedef struct {} A
;
1493 typedef struct {} const C
; // #cwg389-C
1494 typedef enum {} const D
; // #cwg389-D
1496 template<typename
> struct T
{};
1498 struct WithLinkage1
{};
1499 enum WithLinkage2
{};
1500 typedef struct {} *WithLinkage3a
, WithLinkage3b
;
1501 typedef enum {} WithLinkage4a
, *WithLinkage4b
;
1502 typedef S::A WithLinkage5
;
1503 typedef const S::B WithLinkage6
;
1504 typedef int WithLinkage7
;
1505 typedef void (*WithLinkage8
)(WithLinkage2
WithLinkage1::*, WithLinkage5
*);
1506 typedef T
<WithLinkage5
> WithLinkage9
;
1508 typedef struct {} *WithoutLinkage1
; // #cwg389-no-link-1
1509 typedef enum {} const WithoutLinkage2
; // #cwg389-no-link-2
1510 // These two types don't have linkage even though they are externally visible
1511 // and the ODR requires them to be merged across TUs.
1512 typedef S::C WithoutLinkage3
;
1513 typedef S::D WithoutLinkage4
;
1514 typedef void (*WithoutLinkage5
)(int (WithoutLinkage3::*)(char));
1516 #if __cplusplus >= 201103L
1517 // This has linkage even though its template argument does not.
1518 // FIXME: This is probably a defect.
1519 typedef T
<WithoutLinkage1
> WithLinkage10
;
1521 typedef int WithLinkage10
; // dummy
1523 typedef T
<WithLinkage1
> GoodArg1
;
1524 typedef T
<WithLinkage2
> GoodArg2
;
1525 typedef T
<WithLinkage3a
> GoodArg3a
;
1526 typedef T
<WithLinkage3b
> GoodArg3b
;
1527 typedef T
<WithLinkage4a
> GoodArg4a
;
1528 typedef T
<WithLinkage4b
> GoodArg4b
;
1529 typedef T
<WithLinkage5
> GoodArg5
;
1530 typedef T
<WithLinkage6
> GoodArg6
;
1531 typedef T
<WithLinkage7
> GoodArg7
;
1532 typedef T
<WithLinkage8
> GoodArg8
;
1533 typedef T
<WithLinkage9
> GoodArg9
;
1535 typedef T
<WithoutLinkage1
> BadArg1
;
1536 // expected-error@-1 {{template argument uses unnamed type}}
1537 // expected-note@#cwg389-no-link-1 {{unnamed type used in template argument was declared here}}
1538 typedef T
<WithoutLinkage2
> BadArg2
;
1539 // expected-error@-1 {{template argument uses unnamed type}}
1540 // expected-note@#cwg389-no-link-2 {{unnamed type used in template argument was declared here}}
1541 typedef T
<WithoutLinkage3
> BadArg3
;
1542 // expected-error@-1 {{template argument uses unnamed type}}
1543 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1544 typedef T
<WithoutLinkage4
> BadArg4
;
1545 // expected-error@-1 {{template argument uses unnamed type}}
1546 // expected-note@#cwg389-D {{unnamed type used in template argument was declared here}}
1547 typedef T
<WithoutLinkage5
> BadArg5
;
1548 // expected-error@-1 {{template argument uses unnamed type}}
1549 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1552 extern WithLinkage1 withLinkage1
;
1553 extern WithLinkage2 withLinkage2
;
1554 extern WithLinkage3a withLinkage3a
;
1555 extern WithLinkage3b withLinkage3b
;
1556 extern WithLinkage4a withLinkage4a
;
1557 extern WithLinkage4b withLinkage4b
;
1558 extern WithLinkage5 withLinkage5
;
1559 extern WithLinkage6 withLinkage6
;
1560 extern WithLinkage7 withLinkage7
;
1561 extern WithLinkage8 withLinkage8
;
1562 extern WithLinkage9 withLinkage9
;
1563 extern WithLinkage10 withLinkage10
;
1565 // FIXME: These are all ill-formed.
1566 extern WithoutLinkage1 withoutLinkage1
;
1567 extern WithoutLinkage2 withoutLinkage2
;
1568 extern WithoutLinkage3 withoutLinkage3
;
1569 extern WithoutLinkage4 withoutLinkage4
;
1570 extern WithoutLinkage5 withoutLinkage5
;
1574 extern WithoutLinkage1 cwg389_withoutLinkage1
;
1575 extern WithoutLinkage2 cwg389_withoutLinkage2
;
1576 extern WithoutLinkage3 cwg389_withoutLinkage3
;
1577 extern WithoutLinkage4 cwg389_withoutLinkage4
;
1578 extern WithoutLinkage5 cwg389_withoutLinkage5
;
1582 WithoutLinkage1 withoutLinkageDef1
;
1583 WithoutLinkage2 withoutLinkageDef2
= WithoutLinkage2();
1584 WithoutLinkage3 withoutLinkageDef3
= {};
1585 WithoutLinkage4 withoutLinkageDef4
= WithoutLinkage4();
1586 WithoutLinkage5 withoutLinkageDef5
;
1588 void use(const void *);
1590 use(&withLinkage1
); use(&withLinkage2
); use(&withLinkage3a
); use(&withLinkage3b
);
1591 use(&withLinkage4a
); use(&withLinkage4b
); use(&withLinkage5
); use(&withLinkage6
);
1592 use(&withLinkage7
); use(&withLinkage8
); use(&withLinkage9
); use(&withLinkage10
);
1594 use(&withoutLinkage1
); use(&withoutLinkage2
); use(&withoutLinkage3
);
1595 use(&withoutLinkage4
); use(&withoutLinkage5
);
1597 use(&cwg389_withoutLinkage1
); use(&cwg389_withoutLinkage2
);
1598 use(&cwg389_withoutLinkage3
); use(&cwg389_withoutLinkage4
);
1599 use(&cwg389_withoutLinkage5
);
1601 use(&withoutLinkageDef1
); use(&withoutLinkageDef2
); use(&withoutLinkageDef3
);
1602 use(&withoutLinkageDef4
); use(&withoutLinkageDef5
);
1606 // FIXME: This is ill-formed.
1607 extern WithoutLinkage1 withoutLinkageLocal
;
1611 namespace cwg390
{ // cwg390: 3.3
1612 template<typename T
>
1615 // expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg390::A<int>'}}
1616 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::A' requested here}}
1617 // expected-note@#cwg390-f {{'f' declared here}}
1618 virtual void f() = 0; // #cwg390-f
1621 template<typename T
> A
<T
>::~A() { T::error
; }
1622 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1623 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::~A' requested here}}
1624 template<typename T
> void A
<T
>::f() { T::error
; } // ok, not odr-used
1625 struct B
: A
<int> { // #cwg390-A-int
1630 namespace cwg391
{ // cwg391: 2.8 c++11
1631 // FIXME: Should this apply to C++98 too?
1632 class A
{ A(const A
&); }; // #cwg391-A
1635 // cxx98-error@-1 {{C++98 requires an accessible copy constructor for class 'cwg391::A' when binding a reference to a temporary; was private}}
1636 // cxx98-note@#cwg391-A {{implicitly declared private here}}
1638 struct B
{ B(const B
&) = delete; }; // #cwg391-B
1639 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1642 // cxx98-error@-1 {{copying variable of type 'B' invokes deleted constructor}}
1643 // cxx98-note@#cwg391-B {{'B' has been explicitly marked deleted here}}
1645 template<typename T
>
1647 C(const C
&) { T::error
; }
1650 const C
<int> &c
= fc();
1653 // cwg392 is in cwg392.cpp
1655 namespace cwg393
{ // cwg393: 2.7
1656 template <typename T
>
1659 void f1(S
<int (*)[]>);
1660 void f2(S
<int (&)[]>);
1661 void g(int(*S
<int>::*)[]);
1663 template<typename T
>
1664 void sp_assert_convertible( T
* ) {}
1666 template<typename T
, typename U
>
1668 T (*p
) [] = (U(*)[])0;
1669 sp_assert_convertible
<T
[]>( (U(*)[])0 );
1671 } // namespace cwg393
1675 namespace cwg395
{ // cwg395: 3.0
1677 template <typename T
, int N
>(&operator T())[N
];
1678 // expected-error@-1 {{cannot specify any part of a return type in the declaration of a conversion function}}
1679 template <typename T
, int N
> operator(T (&)[N
])();
1680 // expected-error@-1 {{expected ')'}}
1681 // expected-note@-2 {{to match this '('}}
1682 // expected-error@-3 {{a type specifier is required for all declarations}}
1683 template <typename T
> operator T
*() const { return 0; }
1684 template <typename T
, typename U
> operator T
U::*() const { return 0; }
1685 template <typename T
, typename U
> operator T (U::*)()() const { return 0; }
1686 // expected-error@-1 {{a type specifier is required for all declarations}}
1687 // expected-error@-2 {{conversion function cannot have any parameters}}
1688 // expected-error@-3 {{cannot specify any part of a return type in the declaration of a conversion function}}
1689 // expected-error@-4 {{conversion function cannot convert to a function type}}
1694 template <class T
, class U
> struct ptr_mem_fun_t
{
1695 typedef T (U::*type
)();
1698 template <class T
, class U
>
1699 operator typename ptr_mem_fun_t
<T
, U
>::type() const { // #cwg395-conv-func
1703 int (S::*p
)() = null1
;
1704 // expected-error@-1 {{no viable conversion from 'struct null1_t' to 'int (cwg395::S::*)()'}}
1705 // expected-note@#cwg395-conv-func {{candidate template ignored: couldn't infer template argument 'T'}}
1707 template <typename T
> using id
= T
;
1708 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1711 template <typename T
, int N
> operator id
<T
[N
]> &();
1712 template <typename T
, typename U
> operator id
<T (U::*)()>() const;
1716 template<class T
, class U
> using ptr_mem_fun_t
= T (U::*)();
1717 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1718 template<class T
, class U
> operator ptr_mem_fun_t
<T
, U
>() const { return 0; };
1720 int (S::*q
)() = null2
;
1723 namespace cwg396
{ // cwg396: yes
1726 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1727 // expected-error@-2 {{illegal storage class on function}}
1728 int (i
); // #cwg396-i
1730 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1731 // expected-error@-2 {{redefinition of 'i'}}
1732 // expected-note@#cwg396-i {{previous definition is here}}
1738 namespace cwg398
{ // cwg398: yes
1739 namespace example1
{
1741 static int const I
= 42;
1743 template <int N
> struct X
{};
1744 template <typename T
> void f(X
<T::I
> *) {}
1745 template <typename T
> void f(X
<T::J
> *) {}
1746 void foo() { f
<S
>(0); }
1749 namespace example2
{
1750 template <int I
> struct X
{};
1751 template <template <class T
> class> struct Z
{};
1752 template <class T
> void f(typename
T::Y
*) {} // #cwg398-f
1753 template <class T
> void g(X
<T::N
> *) {} // #cwg398-g
1754 template <class T
> void h(Z
<T::template TT
> *) {} // #cwg398-h
1768 // expected-error@-1 {{no matching function for call to 'f'}}
1769 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = A]: no type named 'Y' in 'cwg398::example2::A'}}
1771 // expected-error@-1 {{no matching function for call to 'f'}}
1772 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = B]: typename specifier refers to non-type member 'Y' in 'cwg398::example2::B'}}
1774 // expected-error@-1 {{no matching function for call to 'g'}}
1775 // expected-note@#cwg398-g {{candidate template ignored: substitution failure [with T = C]: missing 'typename' prior to dependent type name 'C::N'}}
1777 // expected-error@-1 {{no matching function for call to 'h'}}
1778 // expected-note@#cwg398-h {{candidate template ignored: substitution failure [with T = D]: 'TT' following the 'template' keyword does not refer to a template}}
1783 namespace cwg399
{ // cwg399: 11
1784 // NB: reuse cwg244 test
1785 struct B
{}; // #cwg399-B
1790 B
* B_ptr
= &D_object
;
1794 // expected-error@-1 {{destructor type 'cwg399::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
1795 // expected-note@#cwg399-B {{type 'cwg399::B' found by destructor name lookup}}
1797 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
1800 B_ptr
->B_alias::~B();
1801 B_ptr
->B_alias::~B_alias();
1802 B_ptr
->cwg399::~B();
1803 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1804 B_ptr
->cwg399::~B_alias();
1805 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1808 template<typename T
, typename U
>
1809 void f(T
*B_ptr
, U D_object
) {
1810 D_object
.~B(); // FIXME: Missing diagnostic for this.
1812 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
1815 B_ptr
->B_alias::~B();
1816 B_ptr
->B_alias::~B_alias();
1817 B_ptr
->cwg399::~B();
1818 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1819 B_ptr
->cwg399::~B_alias();
1820 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1822 template void f
<B
, D
>(B
*, D
);
1825 template<typename T
> struct E
{};
1829 typedef N::F G
; // #cwg399-G
1832 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1834 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
1836 // This is technically ill-formed; E is looked up in 'N::' and names the
1837 // class template, not the injected-class-name of the class. But that's
1838 // probably a bug in the standard.
1840 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1841 // This is valid; we look up the second F in the same scope in which we
1842 // found the first one, that is, 'N::'.
1844 // This is technically ill-formed; G is looked up in 'N::' and is not found.
1845 // Rejecting this seems correct, but most compilers accept, so we do also.
1847 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
1848 // expected-note@#cwg399-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
1851 // Bizarrely, compilers perform lookup in the scope for qualified destructor
1852 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
1854 namespace QualifiedLookupInScope
{
1856 template <typename
> struct S
{ struct Inner
{}; };
1858 template <typename U
> void f(typename
N::S
<U
>::Inner
*p
) {
1859 typedef typename
N::S
<U
>::Inner T
;
1860 p
->::cwg399::QualifiedLookupInScope::N::S
<U
>::Inner::~T();
1861 // expected-error@-1 {{no type named 'T' in 'cwg399::QualifiedLookupInScope::N::S<int>'}}
1862 // expected-note@#cwg399-f {{in instantiation of function template specialization 'cwg399::QualifiedLookupInScope::f<int>' requested here}}
1864 template void f
<int>(N::S
<int>::Inner
*); // #cwg399-f
1866 template <typename U
> void g(U
*p
) {
1870 p
->::cwg399::QualifiedLookupInScope::N::S
<int>::Inner::~T();
1871 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
1873 template void g(N::S
<int>::Inner
*);