1 // RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_23,cxx23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98_20,cxx20_23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
8 namespace dr300
{ // dr300: yes
9 template<typename R
, typename A
> void f(R (&)(A
)) {}
14 namespace dr301
{ // dr301: yes
17 template<typename T
> void operator+(T
, T
);
21 bool a
= (void(*)(S
, S
))operator+<S
> < // expected-warning {{ordered comparison of function pointers}}
22 (void(*)(S
, S
))operator+<S
>;
23 bool b
= (void(*)(S
, S
))operator- < // cxx20_23-note {{to match this '<'}} cxx98_17-warning {{ordered comparison of function pointers}}
24 (void(*)(S
, S
))operator-; // cxx20_23-error {{expected '>'}}
25 bool c
= (void(*)(S
, S
))operator+ < // expected-note {{to match this '<'}}
26 (void(*)(S
, S
))operator-; // expected-error {{expected '>'}}
29 template<typename T
> void f() {
30 typename
T::template operator+<int> a
; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
31 // FIXME: This shouldn't say (null).
32 class T::template operator+<int> b
; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
33 enum T::template operator+<int> c
; // expected-error {{expected identifier}}
34 enum T::template operator+<int>::E d
; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
35 enum T::template X
<int>::E e
;
36 T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
37 T::template operator+<int>(0); // ok
40 template<typename T
> class operator&<T
*> {}; // expected-error +{{}}
41 template<typename T
> class T::operator& {}; // expected-error +{{}}
42 template<typename T
> class S::operator&<T
*> {}; // expected-error +{{}}
45 namespace dr302
{ // dr302: yes
46 struct A
{ A(); ~A(); };
47 #if __cplusplus < 201103L
48 struct B
{ // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
49 const int n
; // expected-note {{declared here}}
51 } b
= B(); // expected-note {{first required here}}
52 // Trivial default constructor C::C() is not called here.
58 const int n
; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
60 } b
= B(); // expected-error {{call to implicitly-deleted default constructor}}
61 // C::C() is called here, because even though it's trivial, it's deleted.
63 const int n
; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
64 } c
= C(); // expected-error {{call to implicitly-deleted default constructor}}
73 namespace dr304
{ // dr304: yes
75 int n
= a(); // expected-error {{requires an initializer}}
79 #if __cplusplus < 201103L
80 // expected-error@-3 {{requires an initializer}}
81 // expected-note@-3 {{in value-initialization}}
83 // expected-error@-5 {{deleted}}
84 // expected-note@-7 {{reference}}
88 namespace dr305
{ // dr305: no
103 struct B
{}; // expected-note {{type 'B' found by destructor name lookup}}
104 b
->~B(); // expected-error {{does not match}}
107 template<typename T
> struct X
{};
112 x
->~X
<char>(); // expected-error {{no member named}}
115 #if __cplusplus >= 201103L
117 template<typename T
> using T1
= Y
;
119 template<typename T
> using T2
= Y
;
125 template<typename T
> using T2
= T
;
128 z
->~T1
<int>(); // expected-error {{no member named 'T1' in 'dr305::Z'}}
129 z
->~T2
<int>(); // expected-error {{no member named '~int'}}
133 // FIXME: This is valid.
135 template<typename A
> struct R
{};
137 template<typename A
> using R
= Q::R
<int>;
138 void qr(Q::R
<int> x
) { x
.~R
<char>(); } // expected-error {{no member named}}
142 namespace dr306
{ // dr306: dup 39
143 struct A
{ struct B
{}; };
144 struct C
{ typedef A::B B
; };
145 struct D
: A
, A::B
, C
{};
148 struct X
{}; // expected-note {{member type 'dr306::X' found}}
149 template<typename T
> struct Y
{ typedef T X
; }; // expected-note {{member type 'const dr306::X' found}}
150 template<typename T
> struct Z
: X
, Y
<T
> {};
152 Z
<const X
>::X zcx
; // expected-error {{member 'X' found in multiple base classes of different types}}
157 namespace dr308
{ // dr308: yes
158 // This is mostly an ABI library issue.
164 // NB: the warning here is correct despite being the opposite of the
165 // comments in the catch handlers. The "unreachable" comment is correct
166 // because there is an ambiguous base path to A from the D that is thrown.
167 // The warnings generated are also correct because the handlers handle
168 // const B& and const A& and we don't check to see if other derived classes
169 // exist that would cause an ambiguous base path. We issue the diagnostic
170 // despite the potential for a false positive because users are not
171 // expected to have ambiguous base paths all that often, so the false
172 // positive rate should be acceptably low.
175 } catch (const A
&) { // expected-note {{for type 'const A &'}}
177 } catch (const B
&) { // expected-warning {{exception of type 'const B &' will be caught by earlier handler}}
185 namespace dr311
{ // dr311: yes
186 namespace X
{ namespace Y
{} }
188 #if __cplusplus <= 201402L
189 // expected-error@-2 {{define each namespace separately}}
193 #if __cplusplus <= 201402L
194 // expected-error@-2 {{define each namespace separately}}
197 // FIXME: The diagnostics here are not very good.
198 namespace ::dr311::X
{} // expected-error 2+{{}} // expected-warning {{extra qual}}
203 namespace dr313
{ // dr313: dup 299 c++11
204 struct A
{ operator int() const; };
205 int *p
= new int[A()];
206 #if __cplusplus < 201103L
207 // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
211 namespace dr314
{ // dr314: no
213 template <typename T
> struct A
{
214 template <typename U
> struct B
{};
216 template <typename T
> struct C
: public A
<T
>::template B
<T
> {
217 C() : A
<T
>::template B
<T
>() {}
219 template <typename T
> struct C2
: public A
<T
>::B
<T
> {
220 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
221 C2() : A
<T
>::B
<T
>() {}
222 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
229 namespace dr317
{ // dr317: 3.5
230 void f() {} // expected-note {{previous}}
231 inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
235 inline int g() { return 0; }
239 int h() { return 0; } // expected-note {{previous}}
240 inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
243 namespace dr318
{ // dr318: sup 1310
248 namespace dr319
{ // dr319: no
250 // FIXME: We don't have a diagnostic for a name with linkage
251 // having a type without linkage.
255 extern "C" void f(ps
);
256 void g(ps
); // FIXME: ill-formed, type 'ps' has no linkage
258 static enum { e
} a1
;
259 enum { e2
} a2
; // FIXME: ill-formed, enum type has no linkage
262 typedef int (*pa
)[n1
];
263 pa parr
; // ok, type has linkage despite using 'n1'
265 template<typename
> struct X
{};
269 extern A a
; // FIXME: ill-formed
273 extern B b
; // FIXME: ill-formed
281 #if __cplusplus < 201103L
282 // expected-error@-12 {{uses local type 'A'}}
283 // expected-error@-9 {{uses local type 'A'}}
287 namespace dr320
{ // dr320: yes
288 #if __cplusplus >= 201103L
291 constexpr X(const X
&x
) : copies(x
.copies
+ 1) {}
294 constexpr X
f(X x
) { return x
; }
295 constexpr unsigned g(X x
) { return x
.copies
; }
296 static_assert(f(X()).copies
== g(X()) + 1, "expected one extra copy for return value");
300 namespace dr321
{ // dr321: dup 557
302 template<int> struct A
{
303 template<int> struct B
;
305 template<> template<> struct A
<0>::B
<0>;
308 template<> template<> struct N::A
<0>::B
<0> {};
310 template<typename T
> void g(T t
) { f(t
); }
311 template void g(N::A
<0>::B
<0>);
314 template<typename
> struct I
{ friend bool operator==(const I
&, const I
&); };
320 namespace dr322
{ // dr322: yes
322 template<typename T
> operator T
&();
324 int &r
= static_cast<int&>(a
);
330 namespace dr324
{ // dr324: yes
331 struct S
{ int n
: 1; } s
; // expected-note 3{{bit-field is declared here}}
332 int &a
= s
.n
; // expected-error {{non-const reference cannot bind to bit-field}}
333 int *b
= &s
.n
; // expected-error {{address of bit-field}}
334 int &c
= (s
.n
= 0); // expected-error {{non-const reference cannot bind to bit-field}}
335 int *d
= &(s
.n
= 0); // expected-error {{address of bit-field}}
336 int &e
= true ? s
.n
: s
.n
; // expected-error {{non-const reference cannot bind to bit-field}}
337 int *f
= &(true ? s
.n
: s
.n
); // expected-error {{address of bit-field}}
338 int &g
= (void(), s
.n
); // expected-error {{non-const reference cannot bind to bit-field}}
339 int *h
= &(void(), s
.n
); // expected-error {{address of bit-field}}
340 int *i
= &++s
.n
; // expected-error {{address of bit-field}}
343 namespace dr326
{ // dr326: yes
345 int test
[__is_trivially_constructible(S
, const S
&) ? 1 : -1];
348 namespace dr327
{ // dr327: dup 538
356 namespace dr328
{ // dr328: yes
357 struct A
; // expected-note 3{{forward declaration}}
358 struct B
{ A a
; }; // expected-error {{incomplete}}
359 template<typename
> struct C
{ A a
; }; // expected-error {{incomplete}}
360 A
*p
= new A
[0]; // expected-error {{incomplete}}
363 namespace dr329
{ // dr329: 3.5
365 template<typename T
> struct A
: B
{
366 friend void f(A a
) { g(a
); }
367 friend void h(A a
) { g(a
); } // expected-error {{undeclared}}
368 friend void i(B b
) {} // expected-error {{redefinition}} expected-note {{previous}}
371 A
<char> b
; // expected-note {{instantiation}}
374 h(a
); // expected-note {{instantiation}}
378 namespace dr330
{ // dr330: 7
379 // Conversions between P and Q will be allowed by P0388.
380 typedef int *(*P
)[3];
381 typedef const int *const (*Q
)[3];
382 typedef const int *Qinner
[3];
383 typedef Qinner
const *Q2
; // same as Q, but 'const' written outside the array type
384 typedef const int *const (*R
)[4];
385 typedef const int *const (*S
)[];
386 typedef const int *(*T
)[];
387 void f(P p
, Q q
, Q2 q2
, R r
, S s
, T t
) {
390 r
= p
; // expected-error {{incompatible}}
392 #if __cplusplus < 202002
393 // expected-error@-2 {{incompatible}} (fixed by p0388)
395 t
= p
; // expected-error {{incompatible}}
397 #if __cplusplus < 202002
398 // expected-error@-2 {{incompatible}} (fixed by p0388)
401 #if __cplusplus < 202002
402 // expected-error@-2 {{incompatible}} (fixed by p0388)
404 s
= t
; // ok, adding const
405 t
= s
; // expected-error {{discards qualifiers}}
406 (void) const_cast<P
>(q
);
407 (void) const_cast<P
>(q2
);
408 (void) const_cast<Q
>(p
);
409 (void) const_cast<Q2
>(p
);
410 (void) const_cast<S
>(p
); // expected-error {{not allowed}} (for now)
411 (void) const_cast<P
>(s
); // expected-error {{not allowed}} (for now)
412 (void) const_cast<S
>(q
); // expected-error {{not allowed}}
413 (void) const_cast<S
>(q2
); // expected-error {{not allowed}}
414 (void) const_cast<Q
>(s
); // expected-error {{not allowed}}
415 (void) const_cast<Q2
>(s
); // expected-error {{not allowed}}
416 (void) const_cast<T
>(s
);
417 (void) const_cast<S
>(t
);
418 (void) const_cast<T
>(q
); // expected-error {{not allowed}}
419 (void) const_cast<Q
>(t
); // expected-error {{not allowed}}
421 (void) reinterpret_cast<P
>(q
); // expected-error {{casts away qualifiers}}
422 (void) reinterpret_cast<P
>(q2
); // expected-error {{casts away qualifiers}}
423 (void) reinterpret_cast<Q
>(p
);
424 (void) reinterpret_cast<Q2
>(p
);
425 (void) reinterpret_cast<S
>(p
);
426 (void) reinterpret_cast<P
>(s
); // expected-error {{casts away qualifiers}}
427 (void) reinterpret_cast<S
>(q
);
428 (void) reinterpret_cast<S
>(q2
);
429 (void) reinterpret_cast<Q
>(s
);
430 (void) reinterpret_cast<Q2
>(s
);
431 (void) reinterpret_cast<T
>(s
); // expected-error {{casts away qualifiers}}
432 (void) reinterpret_cast<S
>(t
);
433 (void) reinterpret_cast<T
>(q
); // expected-error {{casts away qualifiers}}
434 (void) reinterpret_cast<Q
>(t
);
437 namespace swift_17882
{
438 typedef const char P
[72];
440 void f(P
&pr
, P
*pp
) {
441 (void) reinterpret_cast<const Q
&>(pr
);
442 (void) reinterpret_cast<const Q
*>(pp
);
446 typedef const volatile int A
[1][2][3];
447 typedef int *const X::*volatile *B1
;
448 typedef int *const X::* *B2
;
449 typedef int *X::* volatile *B3
;
450 typedef volatile int *(*const B4
)[4];
452 (void) reinterpret_cast<B1
*>(a
);
453 (void) reinterpret_cast<B2
*>(a
); // expected-error {{casts away qualifiers}}
454 (void) reinterpret_cast<B3
*>(a
); // expected-error {{casts away qualifiers}}
455 (void) reinterpret_cast<B4
*>(a
);
460 namespace dr331
{ // dr331: yes
462 A(volatile A
&); // expected-note 2{{candidate}}
463 } const a
, b(a
); // expected-error 2{{no matching constructor}}
466 namespace dr332
{ // dr332: dup 577
467 void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
468 // cxx20_23-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
469 void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
470 void h(int n
, volatile void); // expected-error {{'void' must be the first and only parameter}}
471 // cxx20_23-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
474 namespace dr333
{ // dr333: yes
481 namespace dr334
{ // dr334: yes
482 template<typename T
> void f() {
487 friend S
operator,(S
, int);
490 template void f
<S
>();
495 namespace dr336
{ // dr336: yes
497 template<class T1
> class A
{
498 template<class T2
> class B
{
499 template<class T3
> void mf1(T3
);
503 template<> template<class X
> class A
<int>::B
{};
504 template<> template<> template<class T
> void A
<int>::B
<double>::mf1(T t
) {} // expected-error {{does not match}}
505 template<class Y
> template<> void A
<Y
>::B
<double>::mf2() {} // expected-error {{does not refer into a class}}
508 template<class T1
> class A
{
509 template<class T2
> class B
{
510 template<class T3
> void mf1(T3
);
514 template<> template<class X
> class A
<int>::B
{
515 template<class T
> void mf1(T
);
517 template<> template<> template<class T
> void A
<int>::B
<double>::mf1(T t
) {}
518 // FIXME: This diagnostic isn't very good.
519 template<class Y
> template<> void A
<Y
>::B
<double>::mf2() {} // expected-error {{does not refer into a class}}
523 namespace dr337
{ // dr337: yes
524 template<typename T
> void f(T (*)[1]);
525 template<typename T
> int &f(...);
527 struct A
{ virtual ~A() = 0; };
530 // FIXME: The language rules here are completely broken. We cannot determine
531 // whether an incomplete type is abstract. See DR1640, which will probably
532 // supersede this one and remove this rule.
534 int &s
= f
<B
>(0); // expected-error {{of type 'void'}}
535 struct B
{ virtual ~B() = 0; };
538 namespace dr339
{ // dr339: yes
539 template <int I
> struct A
{ static const int value
= I
; };
542 char (&xxx(float))[2];
544 template<class T
> A
<sizeof(xxx((T
)0))> f(T
) {} // expected-note {{candidate}}
549 A
<3> c
= f("foo"); // expected-error {{no matching function}}
556 template <class T
> struct conv_int
{
557 static const bool value
= sizeof(f(T())) == 1;
560 template <class T
> bool conv_int2(A
<sizeof(f(T()))> p
);
562 template<typename T
> A
<sizeof(f(T()))> make_A();
564 int a
[conv_int
<char>::value
? 1 : -1];
565 bool b
= conv_int2
<char>(A
<1>());
566 A
<1> c
= make_A
<char>();
569 namespace dr340
{ // dr340: yes
570 struct A
{ A(int); };
571 struct B
{ B(A
, A
, int); };
576 namespace dr341
{ // dr341: sup 1708
579 extern "C" int &dr341_a
= n
; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
582 extern "C" int &dr341_a
= dr341_a
; // expected-error {{redefinition}}
584 extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
586 int dr341_a
; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
587 int dr341_b
; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
588 int dr341_c
; // expected-note {{declared in global scope here}}
589 int dr341_d
; // expected-note {{declared in global scope here}}
591 extern "C" int dr341_c
; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
592 extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
594 namespace A
{ extern "C" int dr341_e
; } // expected-note {{previous}}
595 namespace B
{ extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
600 namespace dr343
{ // dr343: no
602 template<typename T
> struct A
{
603 template<typename U
> struct B
{};
605 // FIXME: In these contexts, the 'template' keyword is optional.
606 template<typename T
> struct C
: public A
<T
>::B
<T
> { // expected-error {{use 'template'}}
607 C() : A
<T
>::B
<T
>() {} // expected-error {{use 'template'}}
611 namespace dr344
{ // dr344: dup 1435
612 struct A
{ inline virtual ~A(); };
613 struct B
{ friend A::~A(); };
616 namespace dr345
{ // dr345: yes
619 int X
; // expected-note {{here}}
624 template <class T
> void f(T t
) { typename
T::X x
; } // expected-error {{refers to non-type member 'X'}}
627 f(a
); // expected-note {{instantiation}}
633 namespace dr347
{ // dr347: yes
641 struct derived
: base
{};
643 struct derived::nested
{}; // expected-error {{no struct named 'nested'}}
644 int derived::n
; // expected-error {{no member named 'n'}}
645 void derived::f() {} // expected-error {{does not match any}}
646 void derived::g() {} // expected-error {{does not match any}}
651 namespace dr349
{ // dr349: no
653 template <class T
> operator T
***() {
655 return p
; // cxx98_20-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
656 // cxx23-error@-1 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
660 // FIXME: This is valid.
662 const int *const *const *p1
= a
; // expected-note {{in instantiation of}}
665 template <class T
> operator T
***() {
671 // FIXME: This is invalid.
673 const int *const *const *p2
= b
;
678 namespace dr352
{ // dr352: yes
682 template<typename R
, typename A
> void foo(E
, R (*)(A
)); // expected-note 2{{couldn't infer template argument 'R'}}
685 template<typename T
> void arg(T
);
686 template<typename T
> int arg(T
) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
689 foo(e
, &arg
); // expected-error {{no matching function}}
692 foo
<int, int>(e
, &arg
); // expected-error {{deleted}}
698 foo(e
, &arg
); // expected-error {{no matching function}}
701 foo
<int, int>(e
, &arg
); // ok, uses non-template
706 template<int I
> void f1(int (&)[I
]);
707 template<int I
> void f2(int (&)[I
+1]); // expected-note {{couldn't infer}}
708 template<int I
> void f3(int (&)[I
+1], int (&)[I
]);
713 f2(a
); // expected-error {{no matching function}}
717 template<int I
> struct S
{};
718 template<int I
> void g1(S
<I
>);
719 template<int I
> void g2(S
<I
+1>); // expected-note {{couldn't infer}}
720 template<int I
> void g3(S
<I
+1>, S
<I
>);
725 g2(a
); // expected-error {{no matching function}}
729 template<typename T
> void h1(T
= 0); // expected-note {{couldn't infer}}
730 template<typename T
> void h2(T
, T
= 0);
732 h1(); // expected-error {{no matching function}}
738 template<typename T
> int tmpl(T
);
739 template<typename R
, typename A
> void i1(R (*)(A
)); // expected-note 3{{couldn't infer}}
740 template<typename R
, typename A
> void i2(R
, A
, R (*)(A
)); // expected-note {{not viable}}
742 extern int single(int);
746 extern int ambig(float), ambig(int);
747 i1(ambig
); // expected-error {{no matching function}}
750 extern void no_match(float), no_match(int);
751 i1(no_match
); // expected-error {{no matching function}}
752 i2(0, 0, no_match
); // expected-error {{no matching function}}
754 i1(tmpl
); // expected-error {{no matching function}}
759 template<typename T
> struct is_int
;
760 template<> struct is_int
<int> {};
763 template<typename T
> int f(T (*p
)(T
)) { is_int
<T
>(); }
770 template<typename T
> int f(T
, T (*p
)(T
)) { is_int
<T
>(); }
777 template <class T
> int f(T
, T (*p
)(T
)) { is_int
<T
>(); }
779 template <class T
> T
g(T
);
784 template<int I
> class A
{};
785 template<int I
> void g(A
<I
+1>); // expected-note {{couldn't infer}}
786 template<int I
> void f(A
<I
>, A
<I
+1>);
787 void h(A
<1> a1
, A
<2> a2
) {
788 g(a1
); // expected-error {{no matching function}}
795 // dr353 needs an IRGen test.
797 namespace dr354
{ // dr354: yes c++11
798 // FIXME: Should we allow this in C++98 too?
801 template<int*> struct ptr
{}; // expected-note 0-4{{here}}
806 #if __cplusplus < 201103L
807 // expected-error@-5 {{does not refer to any decl}}
808 // expected-error@-5 {{does not refer to any decl}}
809 // expected-error@-5 {{does not refer to any decl}}
810 // expected-error@-5 {{does not refer to any decl}}
811 #elif __cplusplus <= 201402L
812 // expected-error@-10 {{must be cast}}
814 // expected-error@-10 {{does not match}}
815 // expected-error@-10 {{does not match}}
817 // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
819 // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
820 // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
823 template<int*> int both();
824 template<int> int both();
826 int b1
= both
<(int*)0>();
827 #if __cplusplus < 201103L
828 // expected-error@-2 {{no matching function}}
829 // expected-note@-6 {{candidate}}
830 // expected-note@-6 {{candidate}}
833 template<int S::*> struct ptr_mem
{}; // expected-note 0-4{{here}}
835 ptr_mem
<(int S::*)0> m1
;
836 ptr_mem
<(float S::*)0> m2
;
837 ptr_mem
<(int *)0> m3
;
838 #if __cplusplus < 201103L
839 // expected-error@-5 {{cannot be converted}}
840 // expected-error@-5 {{is not a pointer to member constant}}
841 // expected-error@-5 {{cannot be converted}}
842 // expected-error@-5 {{cannot be converted}}
843 #elif __cplusplus <= 201402L
844 // expected-error@-10 {{must be cast}}
846 // expected-error@-10 {{does not match}}
847 // expected-error@-10 {{does not match}}
849 // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
851 // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
852 // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
856 struct dr355_S
; // dr355: yes
857 struct ::dr355_S
{}; // expected-warning {{extra qualification}}
858 namespace dr355
{ struct ::dr355_S s
; }
862 namespace dr357
{ // dr357: yes
863 template<typename T
> struct A
{
864 void f() const; // expected-note {{const qualified}}
866 template<typename T
> void A
<T
>::f() {} // expected-error {{does not match}}
869 template<typename T
> void f();
871 template<typename T
> void B::f() const {} // expected-error {{does not match}}
874 namespace dr358
{ // dr358: yes
875 extern "C" void dr358_f();
878 extern "C" void dr358_f() { var
= 10; }
882 namespace dr359
{ // dr359: yes
883 // Note, the example in the DR is wrong; it doesn't contain an anonymous
893 struct { // expected-error {{extension}}
897 struct S
{ // expected-error {{types cannot be declared in an anonymous union}}
901 union { // expected-error {{extension}}
908 namespace dr360
{ // dr360: yes
919 using A::foo
; // #dr360-foo-using-decl
921 using A::bar
; // #dr360-bar-using-decl
927 int foo
= B().foo(); // expected-error {{is a private member}}
928 // expected-note@#dr360-foo-using-decl {{declared private here}}
929 int bar
= B().bar(); // expected-error {{is a protected member}}
930 // expected-note@#dr360-bar-using-decl {{declared protected here}}
938 namespace dr364
{ // dr364: yes
945 S::f('a'); // expected-error {{call to non-static}}
950 #if "foo" // expected-error {{invalid token}} dr366: yes
953 namespace dr367
{ // dr367: yes
954 // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
955 // array as being a VLA!
956 int a
[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
957 int b
[true ? 4 : throw 0];
958 int c
[true ? *new int : 4]; // expected-error 2{{variable length array}} expected-note {{read of uninitialized}}
959 int d
[true ? 4 : *new int];
960 #if __cplusplus < 201103L
961 // expected-error@-4 2{{variable length array}}
962 // expected-error@-3 2{{variable length array}}
966 namespace dr368
{ // dr368: yes
967 template<typename T
, T
> struct S
{}; // expected-note {{here}}
968 template<typename T
> int f(S
<T
, T()> *); // expected-error {{function type}}
969 template<typename T
> int g(S
<T
, (T())> *); // cxx98_17-note {{type 'X'}}
970 // cxx20_23-note@-1 {{candidate function [with T = dr368::X]}}
971 template<typename T
> int g(S
<T
, true ? T() : T()> *); // cxx98_17-note {{type 'X'}}
972 // cxx20_23-note@-1 {{candidate function [with T = dr368::X]}}
974 int n
= g
<X
>(0); // cxx98_17-error {{no matching}}
975 // cxx20_23-error@-1 {{call to 'g' is ambiguous}}
980 namespace dr372
{ // dr372: no
982 template<typename T
> struct X
{
984 typedef T Type
; // expected-note 2{{protected}}
986 template<typename T
> struct Y
{};
988 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
989 // the protected member T1<T>::Type.
991 template<typename
> class T1
,
992 template<typename
> class T2
> struct Z1
:
994 T2
<typename T1
<T
>::Type
> {}; // expected-error {{protected}}
997 template<typename
> class T1
,
998 template<typename
> class T2
> struct Z2
:
999 T2
<typename T1
<T
>::Type
>, // expected-error {{protected}}
1002 Z1
<int, X
, Y
> z1
; // expected-note {{instantiation of}}
1003 Z2
<int, X
, Y
> z2
; // expected-note {{instantiation of}}
1006 namespace example2
{
1009 typedef int Type
; // expected-note {{private}}
1011 template<typename T
> struct A
{
1012 typename
T::Type t
; // expected-error {{private}}
1014 A
<X
> ax
; // expected-note {{instantiation of}}
1017 namespace example3
{
1020 typedef int N
; // expected-note 2{{protected}}
1023 template<typename T
> struct B
{};
1024 template<typename U
> struct C
: U
, B
<typename
U::N
> {}; // expected-error {{protected}}
1025 template<typename U
> struct D
: B
<typename
U::N
>, U
{}; // expected-error {{protected}}
1027 C
<A
> x
; // expected-note {{instantiation of}}
1028 D
<A
> y
; // expected-note {{instantiation of}}
1031 namespace example4
{
1045 // FIXME: This is valid: deriving from A gives D access to A::B
1046 namespace std_example
{
1049 struct B
{}; // expected-note {{here}}
1051 struct D
: A::B
, A
{}; // expected-error {{protected}}
1054 // FIXME: This is valid: deriving from A::B gives access to A::B!
1058 struct B
; // expected-note {{here}}
1061 struct C
: A::B
{}; // expected-error {{protected}}
1065 namespace dr373
{ // dr373: 5
1066 namespace X
{ int dr373
; }
1067 struct dr373
{ // expected-note {{here}}
1069 using namespace dr373::X
;
1070 int k
= dr373
; // expected-error {{does not refer to a value}}
1072 namespace Y
= dr373::X
;
1077 struct A
{ struct B
{}; }; // expected-note 2{{here}}
1078 namespace X
= A::B
; // expected-error {{expected namespace name}}
1079 using namespace A::B
; // expected-error {{expected namespace name}}
1082 namespace dr374
{ // dr374: yes
1084 template<typename T
> void f();
1085 template<typename T
> struct A
{ void f(); };
1087 template<> void N::f
<char>() {}
1088 template<> void N::A
<char>::f() {}
1089 template<> struct N::A
<int> {};
1095 namespace dr377
{ // dr377: yes
1096 enum E
{ // expected-error {{enumeration values exceed range of largest integer}}
1097 a
= -__LONG_LONG_MAX__
- 1, // expected-error 0-1{{extension}}
1098 b
= 2 * (unsigned long long)__LONG_LONG_MAX__
// expected-error 0-2{{extension}}
1105 namespace dr381
{ // dr381: yes
1109 struct B
: virtual A
{};
1112 struct E
: public C
, public D
{};
1113 struct F
: public A
{};
1116 e
.B::a
= 0; // expected-error {{ambiguous conversion}}
1122 namespace dr382
{ // dr382: yes c++11
1123 // FIXME: Should we allow this in C++98 mode?
1124 struct A
{ typedef int T
; };
1126 typename
dr382::A a
;
1127 #if __cplusplus < 201103L
1128 // expected-error@-3 {{occurs outside of a template}}
1129 // expected-error@-3 {{occurs outside of a template}}
1131 typename A b
; // expected-error {{expected a qualified name}}
1134 namespace dr383
{ // dr383: yes
1135 struct A
{ A
&operator=(const A
&); };
1137 union C
{ C
&operator=(const C
&); };
1139 int check
[(__is_pod(A
) || __is_pod(B
) || __is_pod(C
) || __is_pod(D
)) ? -1 : 1];
1142 namespace dr384
{ // dr384: yes
1144 template<typename T
> struct Base
{};
1145 template<typename T
> struct X
{
1146 struct Y
: public Base
<T
> {
1147 Y
operator+(int) const;
1149 Y
f(unsigned i
) { return Y() + i
; }
1155 template<typename T
> int *operator+(T
, unsigned);
1164 namespace dr385
{ // dr385: yes
1165 struct A
{ protected: void f(); };
1166 struct B
: A
{ using A::f
; };
1167 struct C
: A
{ void g(B b
) { b
.f(); } };
1168 void h(B b
) { b
.f(); }
1170 struct D
{ int n
; }; // expected-note {{member}}
1171 struct E
: protected D
{}; // expected-note {{protected}}
1172 struct F
: E
{ friend int i(E
); };
1173 int i(E e
) { return e
.n
; } // expected-error {{protected member}}
1176 namespace dr387
{ // dr387: yes
1178 template<typename T
> class number
{
1179 number(int); // expected-note 2{{here}}
1180 friend number
gcd(number
&x
, number
&y
) {}
1184 number
<double> a(3), b(4); // expected-error 2{{private}}
1186 b
= gcd(3, 4); // expected-error {{undeclared}}
1191 template <typename T
> class number
{
1194 friend number
gcd(number x
, number y
) { return 0; }
1198 number
<double> a(3), b(4);
1200 b
= gcd(3, 4); // expected-error {{undeclared}}
1205 // FIXME: dr388 needs codegen test
1207 namespace dr389
{ // dr389: no
1209 typedef struct {} A
;
1211 typedef struct {} const C
; // expected-note 0-2{{here}}
1212 typedef enum {} const D
; // expected-note 0-1{{here}}
1214 template<typename
> struct T
{};
1216 struct WithLinkage1
{};
1217 enum WithLinkage2
{};
1218 typedef struct {} *WithLinkage3a
, WithLinkage3b
;
1219 typedef enum {} WithLinkage4a
, *WithLinkage4b
;
1220 typedef S::A WithLinkage5
;
1221 typedef const S::B WithLinkage6
;
1222 typedef int WithLinkage7
;
1223 typedef void (*WithLinkage8
)(WithLinkage2
WithLinkage1::*, WithLinkage5
*);
1224 typedef T
<WithLinkage5
> WithLinkage9
;
1226 typedef struct {} *WithoutLinkage1
; // expected-note 0-1{{here}}
1227 typedef enum {} const WithoutLinkage2
; // expected-note 0-1{{here}}
1228 // These two types don't have linkage even though they are externally visible
1229 // and the ODR requires them to be merged across TUs.
1230 typedef S::C WithoutLinkage3
;
1231 typedef S::D WithoutLinkage4
;
1232 typedef void (*WithoutLinkage5
)(int (WithoutLinkage3::*)(char));
1234 #if __cplusplus >= 201103L
1235 // This has linkage even though its template argument does not.
1236 // FIXME: This is probably a defect.
1237 typedef T
<WithoutLinkage1
> WithLinkage10
;
1239 typedef int WithLinkage10
; // dummy
1241 typedef T
<WithLinkage1
> GoodArg1
;
1242 typedef T
<WithLinkage2
> GoodArg2
;
1243 typedef T
<WithLinkage3a
> GoodArg3a
;
1244 typedef T
<WithLinkage3b
> GoodArg3b
;
1245 typedef T
<WithLinkage4a
> GoodArg4a
;
1246 typedef T
<WithLinkage4b
> GoodArg4b
;
1247 typedef T
<WithLinkage5
> GoodArg5
;
1248 typedef T
<WithLinkage6
> GoodArg6
;
1249 typedef T
<WithLinkage7
> GoodArg7
;
1250 typedef T
<WithLinkage8
> GoodArg8
;
1251 typedef T
<WithLinkage9
> GoodArg9
;
1253 typedef T
<WithoutLinkage1
> BadArg1
; // expected-error{{template argument uses}}
1254 typedef T
<WithoutLinkage2
> BadArg2
; // expected-error{{template argument uses}}
1255 typedef T
<WithoutLinkage3
> BadArg3
; // expected-error{{template argument uses}}
1256 typedef T
<WithoutLinkage4
> BadArg4
; // expected-error{{template argument uses}}
1257 typedef T
<WithoutLinkage5
> BadArg5
; // expected-error{{template argument uses}}
1260 extern WithLinkage1 withLinkage1
;
1261 extern WithLinkage2 withLinkage2
;
1262 extern WithLinkage3a withLinkage3a
;
1263 extern WithLinkage3b withLinkage3b
;
1264 extern WithLinkage4a withLinkage4a
;
1265 extern WithLinkage4b withLinkage4b
;
1266 extern WithLinkage5 withLinkage5
;
1267 extern WithLinkage6 withLinkage6
;
1268 extern WithLinkage7 withLinkage7
;
1269 extern WithLinkage8 withLinkage8
;
1270 extern WithLinkage9 withLinkage9
;
1271 extern WithLinkage10 withLinkage10
;
1273 // FIXME: These are all ill-formed.
1274 extern WithoutLinkage1 withoutLinkage1
;
1275 extern WithoutLinkage2 withoutLinkage2
;
1276 extern WithoutLinkage3 withoutLinkage3
;
1277 extern WithoutLinkage4 withoutLinkage4
;
1278 extern WithoutLinkage5 withoutLinkage5
;
1282 extern WithoutLinkage1 dr389_withoutLinkage1
;
1283 extern WithoutLinkage2 dr389_withoutLinkage2
;
1284 extern WithoutLinkage3 dr389_withoutLinkage3
;
1285 extern WithoutLinkage4 dr389_withoutLinkage4
;
1286 extern WithoutLinkage5 dr389_withoutLinkage5
;
1290 WithoutLinkage1 withoutLinkageDef1
;
1291 WithoutLinkage2 withoutLinkageDef2
= WithoutLinkage2();
1292 WithoutLinkage3 withoutLinkageDef3
= {};
1293 WithoutLinkage4 withoutLinkageDef4
= WithoutLinkage4();
1294 WithoutLinkage5 withoutLinkageDef5
;
1296 void use(const void *);
1298 use(&withLinkage1
); use(&withLinkage2
); use(&withLinkage3a
); use(&withLinkage3b
);
1299 use(&withLinkage4a
); use(&withLinkage4b
); use(&withLinkage5
); use(&withLinkage6
);
1300 use(&withLinkage7
); use(&withLinkage8
); use(&withLinkage9
); use(&withLinkage10
);
1302 use(&withoutLinkage1
); use(&withoutLinkage2
); use(&withoutLinkage3
);
1303 use(&withoutLinkage4
); use(&withoutLinkage5
);
1305 use(&dr389_withoutLinkage1
); use(&dr389_withoutLinkage2
);
1306 use(&dr389_withoutLinkage3
); use(&dr389_withoutLinkage4
);
1307 use(&dr389_withoutLinkage5
);
1309 use(&withoutLinkageDef1
); use(&withoutLinkageDef2
); use(&withoutLinkageDef3
);
1310 use(&withoutLinkageDef4
); use(&withoutLinkageDef5
);
1314 // FIXME: This is ill-formed.
1315 extern WithoutLinkage1 withoutLinkageLocal
;
1319 namespace dr390
{ // dr390: yes
1320 template<typename T
>
1322 A() { f(); } // expected-warning {{call to pure virt}}
1323 virtual void f() = 0; // expected-note {{here}}
1326 template<typename T
> A
<T
>::~A() { T::error
; } // expected-error {{cannot be used prior to}}
1327 template<typename T
> void A
<T
>::f() { T::error
; } // ok, not odr-used
1328 struct B
: A
<int> { // expected-note 2{{in instantiation of}}
1333 namespace dr391
{ // dr391: yes c++11
1334 // FIXME: Should this apply to C++98 too?
1335 class A
{ A(const A
&); }; // expected-note 0-1{{here}}
1338 #if __cplusplus < 201103L
1339 // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1342 struct B
{ B(const B
&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1345 #if __cplusplus < 201103L
1346 // expected-error@-2 {{deleted}}
1349 template<typename T
>
1351 C(const C
&) { T::error
; }
1354 const C
<int> &c
= fc();
1357 // dr392 FIXME write codegen test
1360 namespace dr395
{ // dr395: yes
1362 template <typename T
, int N
>(&operator T())[N
]; // expected-error {{cannot specify any part of a return type}}
1363 template <typename T
, int N
> operator(T (&)[N
])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1364 template <typename T
> operator T
*() const { return 0; }
1365 template <typename T
, typename U
> operator T
U::*() const { return 0; }
1366 template <typename T
, typename U
> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1370 template <class T
, class U
> struct ptr_mem_fun_t
{
1371 typedef T (U::*type
)();
1374 template <class T
, class U
>
1375 operator typename ptr_mem_fun_t
<T
, U
>::type() const { // expected-note {{couldn't infer}}
1379 int (S::*p
)() = null1
; // expected-error {{no viable conversion}}
1381 template <typename T
> using id
= T
; // expected-error 0-1{{extension}}
1384 template <typename T
, int N
> operator id
<T
[N
]> &();
1385 template <typename T
, typename U
> operator id
<T (U::*)()>() const;
1389 template<class T
, class U
> using ptr_mem_fun_t
= T (U::*)(); // expected-error 0-1{{extension}}
1390 template<class T
, class U
> operator ptr_mem_fun_t
<T
, U
>() const { return 0; };
1392 int (S::*q
)() = null2
;
1395 namespace dr396
{ // dr396: yes
1397 auto int a(); // expected-error {{storage class on function}}
1398 int (i
); // expected-note {{previous}}
1399 auto int (i
); // expected-error {{redefinition}}
1400 #if __cplusplus >= 201103L
1401 // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1408 namespace dr398
{ // dr398: yes
1409 namespace example1
{
1411 static int const I
= 42;
1413 template <int N
> struct X
{};
1414 template <typename T
> void f(X
<T::I
> *) {}
1415 template <typename T
> void f(X
<T::J
> *) {}
1416 void foo() { f
<S
>(0); }
1419 namespace example2
{
1420 template <int I
> struct X
{};
1421 template <template <class T
> class> struct Z
{};
1422 template <class T
> void f(typename
T::Y
*) {} // expected-note 2{{substitution failure}}
1423 template <class T
> void g(X
<T::N
> *) {} // expected-note {{substitution failure}}
1424 template <class T
> void h(Z
<T::template TT
> *) {} // expected-note {{substitution failure}}
1437 f
<A
>(0); // expected-error {{no matching function}}
1438 f
<B
>(0); // expected-error {{no matching function}}
1439 g
<C
>(0); // expected-error {{no matching function}}
1440 h
<D
>(0); // expected-error {{no matching function}}
1445 namespace dr399
{ // dr399: 11
1446 // NB: reuse dr244 test
1447 struct B
{}; // expected-note {{type 'dr399::B' found by destructor name lookup}}
1452 B
* B_ptr
= &D_object
;
1455 D_object
.~B(); // expected-error {{does not match the type 'D' of the object being destroyed}}
1457 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
1460 B_ptr
->B_alias::~B();
1461 B_ptr
->B_alias::~B_alias();
1462 B_ptr
->dr399::~B(); // expected-error {{refers to a member in namespace}}
1463 B_ptr
->dr399::~B_alias(); // expected-error {{refers to a member in namespace}}
1466 template<typename T
, typename U
>
1467 void f(T
*B_ptr
, U D_object
) {
1468 D_object
.~B(); // FIXME: Missing diagnostic for this.
1470 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
1473 B_ptr
->B_alias::~B();
1474 B_ptr
->B_alias::~B_alias();
1475 B_ptr
->dr399::~B(); // expected-error {{does not refer to a type name}}
1476 B_ptr
->dr399::~B_alias(); // expected-error {{does not refer to a type name}}
1478 template void f
<B
, D
>(B
*, D
);
1481 template<typename T
> struct E
{};
1485 typedef N::F G
; // expected-note {{found by destructor name lookup}}
1487 f
.G::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1488 f
.G::~F(); // expected-error {{undeclared identifier 'F' in destructor name}}
1490 // This is technically ill-formed; E is looked up in 'N::' and names the
1491 // class template, not the injected-class-name of the class. But that's
1492 // probably a bug in the standard.
1493 f
.N::F::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1494 // This is valid; we look up the second F in the same scope in which we
1495 // found the first one, that is, 'N::'.
1497 // This is technically ill-formed; G is looked up in 'N::' and is not found.
1498 // Rejecting this seems correct, but most compilers accept, so we do also.
1499 f
.N::F::~G(); // expected-error {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
1502 // Bizarrely, compilers perform lookup in the scope for qualified destructor
1503 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
1505 namespace QualifiedLookupInScope
{
1507 template <typename
> struct S
{ struct Inner
{}; };
1509 template <typename U
> void f(typename
N::S
<U
>::Inner
*p
) {
1510 typedef typename
N::S
<U
>::Inner T
;
1511 p
->::dr399::QualifiedLookupInScope::N::S
<U
>::Inner::~T(); // expected-error {{no type named 'T' in}}
1513 template void f
<int>(N::S
<int>::Inner
*); // expected-note {{instantiation of}}
1515 template <typename U
> void g(U
*p
) {
1519 p
->::dr399::QualifiedLookupInScope::N::S
<int>::Inner::~T(); // expected-error {{'T' does not refer to a type name}}
1521 template void g(N::S
<int>::Inner
*);