1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
8 // FIXME: diagnostic above is emitted only on Windows platforms
9 // PR13819 -- __SIZE_TYPE__ is incompatible.
10 typedef __SIZE_TYPE__
size_t;
11 // cxx98-error@-1 0-1 {{'long long' is a C++11 extension}}
13 #if __cplusplus == 199711L
14 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
15 // cxx98-error@-1 {{variadic macros are a C99 feature}}
18 #if __cplusplus == 199711L
19 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
21 #define __enable_constant_folding
24 namespace cwg200
{ // cwg200: dup 214
25 template <class T
> T
f(int);
26 template <class T
, class U
> T
f(U
) = delete;
27 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
34 // cwg201 is in cwg201.cpp
36 namespace cwg202
{ // cwg202: 3.1
37 template<typename T
> T
f();
38 template<int (*g
)()> struct X
{
39 static_assert(__enable_constant_folding(g
== &f
<int>), "");
46 namespace cwg206
{ // cwg206: yes
47 struct S
; // #cwg206-S
48 template<typename T
> struct Q
{ S s
; };
49 // expected-error@-1 {{field has incomplete type 'S'}}
50 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
51 template<typename T
> void f() { S s
; }
52 // expected-error@-1 {{variable has incomplete type 'S'}}
53 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
56 namespace cwg207
{ // cwg207: yes
71 // cwg208 FIXME: write codegen test
73 namespace cwg209
{ // cwg209: 3.2
75 void f(); // #cwg209-A-f
79 // expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}}
80 // expected-note@#cwg209-A-f {{implicitly declared private here}}
84 // cwg210 is in cwg210.cpp
86 namespace cwg211
{ // cwg211: yes
92 // expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}}
97 namespace cwg213
{ // cwg213: yes
98 template <class T
> struct A
: T
{
102 // expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}}
103 // expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}}
104 // expected-note@#cwg213-B-g {{member is declared here}}
109 int &g(B
); // #cwg213-B-g
113 template void A
<B
>::h(B
); // #cwg213-instantiation
116 namespace cwg214
{ // cwg214: yes
117 template<typename T
, typename U
> T
checked_cast(U from
) { U::error
; }
118 template<typename T
, typename U
> T
checked_cast(U
*from
);
120 void foo(int *arg
) { checked_cast
<const C
*>(arg
); }
122 template<typename T
> T
f(int);
123 template<typename T
, typename U
> T
f(U
) { T::error
; }
129 namespace cwg215
{ // cwg215: 2.9
130 template<typename T
> class X
{
131 friend void T::foo();
135 void foo() { (void)+X
<Y
>().n
; }
139 namespace cwg216
{ // cwg216: no
140 // FIXME: Should reject this: 'f' has linkage but its type does not,
141 // and 'f' is odr-used but not defined in this TU.
142 typedef enum { e
} *E
;
144 void g(E e
) { f(e
); }
147 // FIXME: Should reject this: 'f' has linkage but its type does not,
148 // and 'f' is odr-used but not defined in this TU.
149 typedef enum { e
} *E
;
152 void g(S s
, S::E e
) { s
.f(e
); }
155 namespace cwg217
{ // cwg217: yes
156 template<typename T
> struct S
{
159 template<typename T
> void S
<T
>::f(int = 0) {}
160 // expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}}
163 namespace cwg218
{ // cwg218: yes
176 void test1(A::S as
) { f(as
); }
177 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
178 void test2(A::S as
) { void f(); f(as
); }
179 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
180 // expected-note@-2 {{'f' declared here}}
181 void test3(A::S as
) { using A::f
; f(as
); } // ok
182 void test4(A::S as
) { using B::f
; f(as
); } // ok
183 void test5(A::S as
) { int f
; f(as
); }
184 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
185 void test6(A::S as
) { struct f
{}; (void) f(as
); }
186 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
187 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
188 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
189 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
194 struct X
{ void operator()(S
); } f
;
196 void testD(D::S ds
) { f(ds
); }
197 // expected-error@-1 {{use of undeclared identifier 'f'}}
203 void testE(E::S es
) { f(es
); }
204 // expected-error@-1 {{use of undeclared identifier 'f'}}
208 template<typename T
> friend void f(S
, T
) {}
211 void testF(F::S fs
) { f(fs
, 0); }
219 template<typename T
> void f(T
);
222 template<typename A
, typename B
> struct C
{};
224 void testG(G::C
<G::X::A
, G::Y::B
> gc
) { f(gc
); }
230 namespace cwg221
{ // cwg221: 3.6
231 struct A
{ // #cwg221-S
232 A
&operator=(int&); // #cwg221-S-copy-assign
234 static A
&operator=(A
&, double&);
235 // expected-error@-1 {{overloaded 'operator=' cannot be a static member function}}
236 static A
&operator+=(A
&, double&);
237 // expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}}
238 friend A
&operator=(A
&, char&);
239 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
240 friend A
&operator+=(A
&, char&);
242 A
&operator=(A
&, float&);
243 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
244 A
&operator+=(A
&, float&);
246 void test(A a
, int n
, char c
, float f
) {
250 // expected-error@-1 {{no viable overloaded '='}}
251 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}}
252 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}}
253 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}}
256 // expected-error@-1 {{no viable overloaded '='}}
257 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}}
258 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}}
259 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}}
264 namespace cwg222
{ // cwg222: dup 637
265 void f(int a
, int b
, int c
, int *x
) {
266 #pragma clang diagnostic push
267 #pragma clang diagnostic warning "-Wunsequenced"
269 void((a
+= b
) + (a
+= c
));
270 // expected-warning@-1 {{multiple unsequenced modifications to 'a'}}
273 // cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}}
275 a
= b
= 0; // ok, read and write of 'b' are sequenced
278 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}}
280 #pragma clang diagnostic pop
286 namespace cwg224
{ // cwg224: 16
288 template <class T
> class A
{
293 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
294 ::cwg224::example1::A
<T
>::type d
;
302 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
303 ::cwg224::example1::A
<T
>::type d
;
308 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B::type; implicit 'typename' is a C++20 extension}}
309 typename A
<T
*>::B::type h
;
313 template <class T
> class A
<T
*> {
317 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T>::type; implicit 'typename' is a C++20 extension}}
320 template <class T1
, class T2
, int I
> struct B
{
322 B
<T1
, T2
, I
>::type b1
;
323 B
<T2
, T1
, I
>::type b2
;
324 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<T2, T1, I>::type; implicit 'typename' is a C++20 extension}}
327 static const int my_I
= I
;
328 static const int my_I2
= I
+0;
329 static const int my_I3
= my_I
;
330 B
<my_T1
, T2
, my_I
>::type b3
;
331 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I>::type; implicit 'typename' is a C++20 extension}}
332 B
<my_T1
, T2
, my_I2
>::type b4
;
333 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I2>::type; implicit 'typename' is a C++20 extension}}
334 B
<my_T1
, T2
, my_I3
>::type b5
;
335 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I3>::type; implicit 'typename' is a C++20 extension}}
340 template <int, typename T
> struct X
{ typedef T type
; };
341 template <class T
> class A
{
342 static const int i
= 5;
344 X
<A::i
, char>::type x
;
345 X
<A
<T
>::i
, double>::type y
;
346 X
<A
<T
*>::i
, long>::type z
;
347 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<A<T *>::i, long>::type; implicit 'typename' is a C++20 extension}}
350 template <class T
> int A
<T
>::f() {
357 template<typename T
> void cwg225_f(T t
) { cwg225_g(t
); }
358 // expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
359 // expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}}
360 // expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}}
361 void cwg225_g(int); // #cwg225-g
362 template void cwg225_f(int); // #cwg225-f
364 namespace cwg226
{ // cwg226: no
365 // FIXME: This appears to be wrong: default arguments for function templates
366 // are listed as a defect (in c++98) not an extension. EDG accepts them in
367 // strict c++98 mode.
368 template<typename T
= void> void f() {}
369 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
370 template<typename T
> struct S
{
371 template<typename U
= void> void g();
372 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
373 template<typename U
> struct X
;
374 template<typename U
> void h();
376 template<typename T
> template<typename U
> void S
<T
>::g() {}
377 template<typename T
> template<typename U
= void> struct S
<T
>::X
{};
378 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
379 template<typename T
> template<typename U
= void> void S
<T
>::h() {}
380 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
382 template<typename
> void friend_h();
384 // FIXME: This is ill-formed.
385 template<typename
=void> struct friend_B
;
386 // FIXME: f, h, and i are ill-formed.
387 // f is ill-formed because it is not a definition.
388 // h and i are ill-formed because they are not the only declarations of the
389 // function in the translation unit.
390 template<typename
=void> void friend_f();
391 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
392 template<typename
=void> void friend_g() {}
393 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
394 template<typename
=void> void friend_h() {}
395 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
396 template<typename
=void> void friend_i() {}
397 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
399 template<typename
> void friend_i();
401 template<typename
=void, typename X
> void foo(X
) {}
402 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
403 template<typename
=void, typename X
> struct Foo
{};
404 // expected-error@-1 {{template parameter missing a default argument}}
405 // expected-note@-2 {{previous default template argument defined here}}
407 template<typename
=void, typename X
, typename
, typename Y
> int foo(X
, Y
);
408 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
409 template<typename
, typename X
, typename
=void, typename Y
> int foo(X
, Y
);
410 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
414 void cwg227(bool b
) { // cwg227: yes
421 namespace cwg228
{ // cwg228: yes
422 template <class T
> struct X
{
425 template <class T
> struct Y
{
426 void g(X
<T
> x
) { x
.template X
<T
>::f(); }
430 namespace cwg229
{ // cwg229: 2.9
431 template<typename T
> void f();
432 template<typename T
> void f
<T
*>() {}
433 // expected-error@-1 {{function template partial specialization is not allowed}}
434 template<> void f
<int>() {}
437 namespace cwg230
{ // cwg230: 3.0
440 // 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 'cwg230::S'}}
441 // expected-note@#cwg230-f {{'f' declared here}}
442 virtual void f() = 0; // #cwg230-f
446 namespace cwg231
{ // cwg231: yes
451 void f() { using namespace inner
; }
453 // expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}}
454 // expected-note@#cwg231-i {{'inner::i' declared here}}
461 namespace cwg236
{ // cwg236: 3.2
463 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
464 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
467 namespace cwg237
{ // cwg237: dup 470
468 template<typename T
> struct A
{ void f() { T::error
; } };
469 template<typename T
> struct B
: A
<T
> {};
470 template struct B
<int>; // ok
473 namespace cwg239
{ // cwg239: yes
480 int &g(NS::T
, float);
483 float &r
= g(parm
, 1);
484 extern int &g(NS::T
, float);
491 namespace cwg241
{ // cwg241: yes
494 template <int X
> void f(); // #cwg241-A-f
495 template <int X
> void g(B
);
498 template <class T
> void f(T t
); // #cwg241-C-f
499 template <class T
> void g(T t
); // #cwg241-C-g
503 // expected-error@-1 {{no matching function for call to 'f'}}
504 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
505 // cxx98-17-error@-3 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
507 // cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
509 // expected-error@-1 {{no matching function for call to 'f'}}
510 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
513 // expected-error@-1 {{no matching function for call to 'f'}}
514 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
516 // expected-error@-1 {{no matching function for call to 'g'}}
517 // expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
521 // expected-error@-1 {{no matching function for call to 'f'}}
522 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
523 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
528 namespace cwg243
{ // cwg243: yes
534 operator A() = delete; // #cwg243-B
535 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
539 // expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}}
540 // expected-note@#cwg243-A {{candidate constructor}}
541 // expected-note@#cwg243-B {{candidate function has been explicitly deleted}}
544 namespace cwg244
{ // cwg244: 11
545 // NB: this test is reused by cwg399
546 struct B
{}; // #cwg244-B
551 B
* B_ptr
= &D_object
;
555 // expected-error@-1 {{destructor type 'cwg244::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
556 // expected-note@#cwg244-B {{type 'cwg244::B' found by destructor name lookup}}
558 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
561 B_ptr
->B_alias::~B();
562 B_ptr
->B_alias::~B_alias();
564 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
565 B_ptr
->cwg244::~B_alias();
566 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
569 template<typename T
, typename U
>
570 void f(T
*B_ptr
, U D_object
) {
571 D_object
.~B(); // FIXME: Missing diagnostic for this.
573 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
576 B_ptr
->B_alias::~B();
577 B_ptr
->B_alias::~B_alias();
579 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
580 B_ptr
->cwg244::~B_alias();
581 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
583 template void f
<B
, D
>(B
*, D
);
586 template<typename T
> struct E
{};
590 typedef N::F G
; // #cwg244-G
593 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
595 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
597 // This is technically ill-formed; E is looked up in 'N::' and names the
598 // class template, not the injected-class-name of the class. But that's
599 // probably a bug in the standard.
601 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
602 // This is valid; we look up the second F in the same scope in which we
603 // found the first one, that is, 'N::'.
605 // This is technically ill-formed; G is looked up in 'N::' and is not found.
606 // Rejecting this seems correct, but most compilers accept, so we do also.
608 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
609 // expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
612 // Bizarrely, compilers perform lookup in the scope for qualified destructor
613 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
615 namespace QualifiedLookupInScope
{
617 template <typename
> struct S
{ struct Inner
{}; };
619 template <typename U
> void f(typename
N::S
<U
>::Inner
*p
) {
620 typedef typename
N::S
<U
>::Inner T
;
621 p
->::cwg244::QualifiedLookupInScope::N::S
<U
>::Inner::~T();
622 // expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}}
623 // expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}}
625 template void f
<int>(N::S
<int>::Inner
*); // #cwg244-f
627 template <typename U
> void g(U
*p
) {
631 p
->::cwg244::QualifiedLookupInScope::N::S
<int>::Inner::~T();
632 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
634 template void g(N::S
<int>::Inner
*);
638 namespace cwg245
{ // cwg245: yes
640 enum E
{}; // #cwg245-E
642 // expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}}
643 // expected-note@#cwg245-E {{previous use is here}}
647 namespace cwg246
{ // cwg246: 3.2
649 S() try { // #cwg246-try
654 // expected-error@-1 {{cannot jump from this goto statement to its label}}
655 // expected-note@#cwg246-try {{jump bypasses initialization of try block}}
660 namespace cwg247
{ // cwg247: yes
666 void (A::*f
)() = (void (A::*)())&B::f
;
673 void (C::*g
)() = &D::f
;
674 void (D::*h
)() = &D::f
;
683 void (F::*i
)() = &F::f
;
686 namespace cwg248
{ // cwg248: sup P1949
687 int \u040d\u040e = 0;
690 namespace cwg249
{ // cwg249: yes
691 template<typename T
> struct X
{ void f(); };
692 template<typename T
> void X
<T
>::f() {}
695 namespace cwg250
{ // cwg250: yes
696 typedef void (*FPtr
)(double x
[]);
698 template<int I
> void f(double x
[]);
701 template<int I
= 3> void g(double x
[]);
702 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
706 namespace cwg252
{ // cwg252: 3.1
708 void operator delete(void*); // #cwg252-A
711 void operator delete(void*); // #cwg252-B
717 // expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}}
718 // expected-note@#cwg252-A {{member found by ambiguous name lookup}}
719 // expected-note@#cwg252-B {{member found by ambiguous name lookup}}
722 void operator delete(void*, int); // #cwg252-D
726 // expected-error@-1 {{no suitable member 'operator delete' in 'D'}}
727 // expected-note@#cwg252-D {{member 'operator delete' declared here}}
730 void operator delete(void*, int);
731 void operator delete(void*) = delete; // #cwg252-E
732 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
736 // expected-error@-1 {{attempt to use a deleted function}}
737 // expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}}
740 // If both functions are available, the first one is a placement delete.
741 void operator delete(void*, size_t);
742 void operator delete(void*) = delete; // #cwg252-F
743 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
747 // expected-error@-1 {{attempt to use a deleted function}}
748 // expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}}
751 void operator delete(void*, size_t);
757 namespace cwg254
{ // cwg254: 2.9
758 template<typename T
> struct A
{
759 typedef typename
T::type type
; // ok even if this is a typedef-name, because
760 // it's not an elaborated-type-specifier
761 typedef struct T::type foo
;
762 // expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}}
763 // expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}}
764 // expected-note@#cwg254-C {{declared here}}
766 struct B
{ struct type
{}; };
767 struct C
{ typedef struct {} type
; }; // #cwg254-C
769 A
<C
>::type n
; // #cwg254-instantiation
772 namespace cwg255
{ // cwg255: yes
774 void operator delete(void *){};
775 void operator delete(void *, int){};
777 void f(S
*p
) { delete p
; }
778 } // namespace cwg255
782 namespace cwg257
{ // cwg257: 3.4
783 struct A
{ A(int); }; // #cwg257-A
784 struct B
: virtual A
{
786 virtual void f() = 0;
793 // expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}}
794 // expected-note@#cwg257-A {{'cwg257::A' declared here}}
799 namespace cwg258
{ // cwg258: 2.8
802 template<typename
> void g(int);
810 template<int> int &g(int); // #cwg258-B-g
814 int &x
= b
.g
<int>(0);
815 // expected-error@-1 {{no matching member function for call to 'g'}}
816 // expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
818 float &z
= const_cast<const B
&>(b
).h();
821 virtual void f(const int) = 0;
828 virtual void f() = 0; // #cwg258-E-f
833 // expected-error@-1 {{variable type 'struct F' is an abstract class}}
834 // expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}}
837 namespace cwg259
{ // cwg259: 4
838 template<typename T
> struct A
{};
839 template struct A
<int>; // #cwg259-A-int
840 template struct A
<int>;
841 // expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}}
842 // expected-note@#cwg259-A-int {{previous explicit instantiation is here}}
844 template<> struct A
<float>; // #cwg259-A-float
845 template struct A
<float>;
846 // expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}}
847 // expected-note@#cwg259-A-float {{previous template specialization is here}}
849 template struct A
<char>; // #cwg259-A-char
850 template<> struct A
<char>;
851 // expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}}
852 // expected-note@#cwg259-A-char {{explicit instantiation first required here}}
854 template<> struct A
<double>;
855 template<> struct A
<double>;
856 template<> struct A
<double> {}; // #cwg259-A-double
857 template<> struct A
<double> {};
858 // expected-error@-1 {{redefinition of 'A<double>'}}
859 // expected-note@#cwg259-A-double {{previous definition is here}}
861 template<typename T
> struct B
; // #cwg259-B
862 template struct B
<int>;
863 // expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}}
864 // expected-note@#cwg259-B {{template is declared here}}
866 template<> struct B
<float>; // #cwg259-B-float
867 template struct B
<float>;
868 // expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}}
869 // expected-note@#cwg259-B-float {{previous template specialization is here}}
872 // FIXME: When cwg260 is resolved, also add tests for CWG507.
874 namespace cwg261
{ // cwg261: no
875 #pragma clang diagnostic push
876 #pragma clang diagnostic warning "-Wused-but-marked-unused"
878 // FIXME: This is ill-formed, with a diagnostic required, because operator new
879 // and operator delete are inline and odr-used, but not defined in this
881 // We're also missing the -Wused-but-marked-unused diagnostic here.
883 inline void *operator new(size_t) __attribute__((unused
));
884 inline void operator delete(void*) __attribute__((unused
));
888 // FIXME: This is ill-formed, with a required diagnostic, for the same
891 inline void operator delete(void*) __attribute__((unused
));
895 inline void operator delete(void*) __attribute__((unused
));
897 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
901 inline void operator delete(void*) __attribute__((unused
));
903 void h() { C::operator delete(0); }
904 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
906 #pragma clang diagnostic pop
909 namespace cwg262
{ // cwg262: yes
916 namespace cwg263
{ // cwg263: 3.3
919 #if __cplusplus < 201103L
920 friend X::X() throw();
921 friend X::~X() throw();
922 #elif __cplusplus <= 201703L
923 friend constexpr X::X() noexcept
;
926 friend constexpr X::X() noexcept
;
927 friend constexpr X::~X();
930 // expected-error@-1 {{extra qualification on member 'Y'}}
932 // expected-error@-1 {{extra qualification on member '~Y'}}
941 namespace cwg272
{ // cwg272: yes
947 // expected-error@-1 {{invalid argument type 'X' to unary expression}}
954 namespace cwg273
{ // cwg273: yes
969 namespace cwg275
{ // cwg275: no
971 template <class T
> void f(T
) {} // #cwg275-N-f
972 template <class T
> void g(T
) {} // #cwg275-N-g
973 template <> void f(int);
974 template <> void f(char);
975 template <> void f(double);
976 template <> void g(char);
982 template <> void N::f(char) {}
983 // expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}}
984 template <class T
> void g(T
) {}
985 template <> void g(char) {}
986 // FIXME: this should be rejected in c++98 too
987 template void f(long);
988 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
989 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
990 // FIXME: this should be rejected in c++98 too
991 template void N::f(unsigned long);
992 // since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
993 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
994 template void h(long);
995 // expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}}
996 template <> void f(double) {}
997 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1000 template <class T
> void g(T
) {} // #cwg275-g
1002 template <> void N::f(char) {}
1003 template <> void f(int) {}
1004 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1006 // FIXME: this should be rejected in c++98 too
1007 template void f(short);
1008 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
1009 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1010 template void N::f(unsigned short);
1012 // FIXME: this should probably be valid. the wording from the issue
1013 // doesn't clarify this, but it follows from the usual rules.
1014 template void g(int);
1015 // expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}}
1016 // expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}}
1017 // expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}}
1019 // FIXME: likewise, this should also be valid.
1020 template<typename T
> void f(T
) {} // #cwg275-f
1021 template void f(short);
1022 // expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}}
1023 // expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}}
1024 // expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}}
1029 namespace cwg277
{ // cwg277: 3.1
1032 static_assert(__enable_constant_folding(!intp()), "");
1035 // cwg279 is in cwg279.cpp
1037 namespace cwg280
{ // cwg280: 2.9
1039 typedef void f1(int);
1040 typedef void f2(int, int);
1041 typedef void f3(int, int, int);
1043 operator f1
*(); // #cwg280-A-f1
1047 operator f0
*(); // #cwg280-B-f0
1049 operator f3
*(); // #cwg280-B-f3
1052 operator f0
*(); // #cwg280-C-f0
1053 operator f1
*(); // #cwg280-C-f1
1054 operator f2
*(); // #cwg280-C-f2
1055 operator f3
*(); // #cwg280-C-f3
1057 struct D
: private A
, B
{ // #cwg280-D
1058 operator f2
*(); // #cwg280-D-f2
1060 struct E
: C
, D
{} e
;
1064 // expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}}
1065 // expected-note@#cwg280-D {{constrained by private inheritance here}}
1066 // expected-note@#cwg280-A-f1 {{member is declared here}}
1067 d(0, 0); // ok, suppressed by member in D
1069 // expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}}
1070 // expected-note@#cwg280-B-f3 {{declared private here}}
1072 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1073 // expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}}
1074 // expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}}
1076 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1077 // expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}}
1078 // expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}}
1080 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1081 // expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1082 // expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1084 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1085 // expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1086 // expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1090 namespace cwg281
{ // cwg281: no
1098 friend inline void a(); // FIXME: ill-formed
1099 friend inline void b();
1100 friend inline void c(); // FIXME: ill-formed
1101 friend inline void d() {}
1102 friend inline void e() {}
1103 friend inline void f() {}
1107 namespace cwg283
{ // cwg283: yes
1108 template<typename T
> // #cwg283-template
1111 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1112 // expected-note@#cwg283-template {{template parameter is declared here}}
1114 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1115 // expected-note@#cwg283-template {{template parameter is declared here}}
1119 namespace cwg284
{ // cwg284: no
1132 // expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}}
1134 struct B::X
{}; // FIXME: ill-formed
1135 enum B::Y e
; // ok per cwg417
1136 class B::Z z
; // ok per cwg417
1150 // expected-error@-1 {{no struct named 'V' in 'cwg284::D'}}
1152 struct D::X
{}; // FIXME: ill-formed
1153 enum D::Y e2
; // ok per cwg417
1154 class D::Z z2
; // ok per cwg417
1157 namespace cwg285
{ // cwg285: yes
1158 template<typename T
> void f(T
, int); // #cwg285-f-T-int
1159 template<typename T
> void f(int, T
); // #cwg285-f-int-T
1160 template<> void f
<int>(int, int) {}
1161 // expected-error@-1 {{function template specialization 'f' ambiguously refers to more than one function template; explicitly specify additional template arguments to identify a particular function template}}
1162 // expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1163 // expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1166 namespace cwg286
{ // cwg286: 2.8
1167 template<class T
> struct A
{
1169 template<class T2
> struct B
{}; // #cwg286-B
1175 struct A
<T
>::C::B
<T2
*> { };
1177 A
<short>::C::B
<int*> absip
;
1178 // expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}}
1179 // expected-note@#cwg286-B {{implicitly declared private here}}
1184 namespace cwg289
{ // cwg289: yes
1185 struct A
; // #cwg289-A
1187 // expected-error@-1 {{base class has incomplete type}}
1188 // expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}}
1190 template<typename T
> struct C
{ typename
T::error error
; };
1191 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1192 // expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}}
1193 struct D
: C
<int> {}; // #cwg289-C-int
1198 // cwg292 is in cwg292.cpp
1200 namespace cwg294
{ // cwg294: no
1201 void f() throw(int);
1202 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1203 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1205 (void)static_cast<void (*)() throw()>(f
); // FIXME: ill-formed in C++14 and before
1206 // FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}}
1208 // Irony: the above is valid in C++17 and beyond, but that's exactly when
1209 // we reject it. In C++14 and before, this is ill-formed because an
1210 // exception-specification is not permitted in a type-id. In C++17, this is
1211 // valid because it's the inverse of a standard conversion sequence
1212 // containing a function pointer conversion. (Well, it's actually not valid
1213 // yet, as a static_cast is not permitted to reverse a function pointer
1214 // conversion, but that is being changed by core issue).
1215 (void)static_cast<void (*)() throw(int)>(f
); // FIXME: ill-formed in C++14 and before
1216 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1217 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1219 void (*p
)() throw() = f
;
1220 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1221 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}}
1222 void (*q
)() throw(int) = f
;
1223 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1224 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1228 namespace cwg295
{ // cwg295: 3.7
1231 // expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}
1233 template<typename T
> struct X
{
1240 // expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}
1243 typedef volatile U
*V
;
1244 // expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}
1247 namespace cwg296
{ // cwg296: yes
1249 static operator int() { return 0; }
1250 // expected-error@-1 {{conversion function must be a non-static member function}}
1254 namespace cwg298
{ // cwg298: 3.1
1260 typedef A B
; // #cwg298-B
1261 typedef const A C
; // #cwg298-C
1269 // expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}}
1270 // expected-note@#cwg298-B {{declared here}}
1272 // expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}}
1273 // expected-note@#cwg298-C {{declared here}}
1276 // expected-error@-1 {{a type specifier is required for all declarations}}
1279 // expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const cwg298::A') of the class name}}
1281 typedef struct D E
; // #cwg298-E
1283 // expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}}
1284 // expected-note@#cwg298-E {{'E' declared here}}
1293 namespace cwg299
{ // cwg299: 2.8 c++11
1298 operator int(); // #cwg299-int
1299 operator unsigned short(); // #cwg299-ushort
1301 // FIXME: should this apply to c++98 mode?
1302 int *p
= new int[S()];
1303 // cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}}
1304 int *q
= new int[T()]; // #cwg299-q
1305 // cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}}
1306 // cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}}
1307 // cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}}
1308 // since-cxx14-error-re@#cwg299-q {{{{conversion from 'T' to 'unsigned (long long|long|int)' is ambiguous}}}}
1309 // since-cxx14-note@#cwg299-int {{candidate function}}
1310 // since-cxx14-note@#cwg299-ushort {{candidate function}}