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
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
9 // FIXME: diagnostic above is emitted only on Windows platforms
10 // PR13819 -- __SIZE_TYPE__ is incompatible.
11 typedef __SIZE_TYPE__
size_t;
12 // cxx98-error@-1 0-1 {{'long long' is a C++11 extension}}
14 #if __cplusplus == 199711L
15 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
16 // cxx98-error@-1 {{variadic macros are a C99 feature}}
19 #if __cplusplus == 199711L
20 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
22 #define __enable_constant_folding
25 namespace cwg200
{ // cwg200: dup 214
26 template <class T
> T
f(int);
27 template <class T
, class U
> T
f(U
) = delete;
28 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
35 // cwg201 is in cwg201.cpp
37 namespace cwg202
{ // cwg202: 3.1
38 template<typename T
> T
f();
39 template<int (*g
)()> struct X
{
40 static_assert(__enable_constant_folding(g
== &f
<int>), "");
47 namespace cwg206
{ // cwg206: yes
48 struct S
; // #cwg206-S
49 template<typename T
> struct Q
{ S s
; };
50 // expected-error@-1 {{field has incomplete type 'S'}}
51 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
52 template<typename T
> void f() { S s
; }
53 // expected-error@-1 {{variable has incomplete type 'S'}}
54 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
57 namespace cwg207
{ // cwg207: yes
72 // cwg208 FIXME: write codegen test
74 namespace cwg209
{ // cwg209: 3.2
76 void f(); // #cwg209-A-f
80 // expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}}
81 // expected-note@#cwg209-A-f {{implicitly declared private here}}
85 // cwg210 is in cwg210.cpp
87 namespace cwg211
{ // cwg211: yes
93 // expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}}
98 namespace cwg213
{ // cwg213: yes
99 template <class T
> struct A
: T
{
103 // expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}}
104 // expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}}
105 // expected-note@#cwg213-B-g {{member is declared here}}
110 int &g(B
); // #cwg213-B-g
114 template void A
<B
>::h(B
); // #cwg213-instantiation
115 } // namespace cwg213
117 namespace cwg214
{ // cwg214: yes
118 template<typename T
, typename U
> T
checked_cast(U from
) { U::error
; }
119 template<typename T
, typename U
> T
checked_cast(U
*from
);
121 void foo(int *arg
) { checked_cast
<const C
*>(arg
); }
123 template<typename T
> T
f(int);
124 template<typename T
, typename U
> T
f(U
) { T::error
; }
128 } // namespace cwg214
130 namespace cwg215
{ // cwg215: 2.9
131 template<typename T
> class X
{
132 friend void T::foo();
136 void foo() { (void)+X
<Y
>().n
; }
138 } // namespace cwg215
140 namespace cwg216
{ // cwg216: no
141 // FIXME: Should reject this: 'f' has linkage but its type does not,
142 // and 'f' is odr-used but not defined in this TU.
143 typedef enum { e
} *E
;
145 void g(E e
) { f(e
); }
148 // FIXME: Should reject this: 'f' has linkage but its type does not,
149 // and 'f' is odr-used but not defined in this TU.
150 typedef enum { e
} *E
;
153 void g(S s
, S::E e
) { s
.f(e
); }
154 } // namespace cwg216
156 namespace cwg217
{ // cwg217: yes
157 template<typename T
> struct S
{
160 template<typename T
> void S
<T
>::f(int = 0) {}
161 // expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}}
162 } // namespace cwg217
164 namespace cwg218
{ // cwg218: yes
177 void test1(A::S as
) { f(as
); }
178 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
179 void test2(A::S as
) { void f(); f(as
); }
180 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
181 // expected-note@-2 {{'f' declared here}}
182 void test3(A::S as
) { using A::f
; f(as
); } // ok
183 void test4(A::S as
) { using B::f
; f(as
); } // ok
184 void test5(A::S as
) { int f
; f(as
); }
185 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
186 void test6(A::S as
) { struct f
{}; (void) f(as
); }
187 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
188 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
189 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
190 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
195 struct X
{ void operator()(S
); } f
;
197 void testD(D::S ds
) { f(ds
); }
198 // expected-error@-1 {{use of undeclared identifier 'f'}}
204 void testE(E::S es
) { f(es
); }
205 // expected-error@-1 {{use of undeclared identifier 'f'}}
209 template<typename T
> friend void f(S
, T
) {}
212 void testF(F::S fs
) { f(fs
, 0); }
220 template<typename T
> void f(T
);
223 template<typename A
, typename B
> struct C
{};
225 void testG(G::C
<G::X::A
, G::Y::B
> gc
) { f(gc
); }
226 } // namespace cwg218
231 namespace cwg221
{ // cwg221: 3.6
232 struct A
{ // #cwg221-S
233 A
&operator=(int&); // #cwg221-S-copy-assign
235 static A
&operator=(A
&, double&);
236 // expected-error@-1 {{overloaded 'operator=' cannot be a static member function}}
237 static A
&operator+=(A
&, double&);
238 // expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}}
239 friend A
&operator=(A
&, char&);
240 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
241 friend A
&operator+=(A
&, char&);
243 A
&operator=(A
&, float&);
244 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
245 A
&operator+=(A
&, float&);
247 void test(A a
, int n
, char c
, float f
) {
251 // expected-error@-1 {{no viable overloaded '='}}
252 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}}
253 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}}
254 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}}
257 // expected-error@-1 {{no viable overloaded '='}}
258 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}}
259 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}}
260 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}}
263 } // namespace cwg221
265 namespace cwg222
{ // cwg222: dup 637
266 void f(int a
, int b
, int c
, int *x
) {
267 #pragma clang diagnostic push
268 #pragma clang diagnostic warning "-Wunsequenced"
270 void((a
+= b
) + (a
+= c
));
271 // expected-warning@-1 {{multiple unsequenced modifications to 'a'}}
274 // cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}}
276 a
= b
= 0; // ok, read and write of 'b' are sequenced
279 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}}
281 #pragma clang diagnostic pop
283 } // namespace cwg222
287 namespace cwg224
{ // cwg224: 16
289 template <class T
> class A
{
294 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
295 ::cwg224::example1::A
<T
>::type d
;
303 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
304 ::cwg224::example1::A
<T
>::type d
;
309 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B::type; implicit 'typename' is a C++20 extension}}
310 typename A
<T
*>::B::type h
;
314 template <class T
> class A
<T
*> {
318 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T>::type; implicit 'typename' is a C++20 extension}}
321 template <class T1
, class T2
, int I
> struct B
{
323 B
<T1
, T2
, I
>::type b1
;
324 B
<T2
, T1
, I
>::type b2
;
325 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<T2, T1, I>::type; implicit 'typename' is a C++20 extension}}
328 static const int my_I
= I
;
329 static const int my_I2
= I
+0;
330 static const int my_I3
= my_I
;
331 B
<my_T1
, T2
, my_I
>::type b3
;
332 // 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}}
333 B
<my_T1
, T2
, my_I2
>::type b4
;
334 // 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}}
335 B
<my_T1
, T2
, my_I3
>::type b5
;
336 // 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}}
341 template <int, typename T
> struct X
{ typedef T type
; };
342 template <class T
> class A
{
343 static const int i
= 5;
345 X
<A::i
, char>::type x
;
346 X
<A
<T
>::i
, double>::type y
;
347 X
<A
<T
*>::i
, long>::type z
;
348 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<A<T *>::i, long>::type; implicit 'typename' is a C++20 extension}}
351 template <class T
> int A
<T
>::f() {
355 } // namespace cwg224
358 template<typename T
> void cwg225_f(T t
) { cwg225_g(t
); }
359 // expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
360 // expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}}
361 // expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}}
362 void cwg225_g(int); // #cwg225-g
363 template void cwg225_f(int); // #cwg225-f
365 namespace cwg226
{ // cwg226: no
366 // FIXME: This appears to be wrong: default arguments for function templates
367 // are listed as a defect (in c++98) not an extension. EDG accepts them in
368 // strict c++98 mode.
369 template<typename T
= void> void f() {}
370 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
371 template<typename T
> struct S
{
372 template<typename U
= void> void g();
373 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
374 template<typename U
> struct X
;
375 template<typename U
> void h();
377 template<typename T
> template<typename U
> void S
<T
>::g() {}
378 template<typename T
> template<typename U
= void> struct S
<T
>::X
{};
379 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
380 template<typename T
> template<typename U
= void> void S
<T
>::h() {}
381 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
383 template<typename
> void friend_h();
385 // FIXME: This is ill-formed.
386 template<typename
=void> struct friend_B
;
387 // FIXME: f, h, and i are ill-formed.
388 // f is ill-formed because it is not a definition.
389 // h and i are ill-formed because they are not the only declarations of the
390 // function in the translation unit.
391 template<typename
=void> void friend_f();
392 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
393 template<typename
=void> void friend_g() {}
394 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
395 template<typename
=void> void friend_h() {}
396 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
397 template<typename
=void> void friend_i() {}
398 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
400 template<typename
> void friend_i();
402 template<typename
=void, typename X
> void foo(X
) {}
403 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
404 template<typename
=void, typename X
> struct Foo
{};
405 // expected-error@-1 {{template parameter missing a default argument}}
406 // expected-note@-2 {{previous default template argument defined here}}
408 template<typename
=void, typename X
, typename
, typename Y
> int foo(X
, Y
);
409 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
410 template<typename
, typename X
, typename
=void, typename Y
> int foo(X
, Y
);
411 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
413 } // namespace cwg226
415 void cwg227(bool b
) { // cwg227: yes
422 namespace cwg228
{ // cwg228: yes
423 template <class T
> struct X
{
426 template <class T
> struct Y
{
427 void g(X
<T
> x
) { x
.template X
<T
>::f(); }
429 } // namespace cwg228
431 namespace cwg229
{ // cwg229: 2.9
432 template<typename T
> void f();
433 template<typename T
> void f
<T
*>() {}
434 // expected-error@-1 {{function template partial specialization is not allowed}}
435 template<> void f
<int>() {}
436 } // namespace cwg229
438 namespace cwg230
{ // cwg230: 3.0
441 // 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'}}
442 // expected-note@#cwg230-f {{'f' declared here}}
443 virtual void f() = 0; // #cwg230-f
445 } // namespace cwg230
447 namespace cwg231
{ // cwg231: yes
452 void f() { using namespace inner
; }
454 // expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}}
455 // expected-note@#cwg231-i {{'inner::i' declared here}}
457 } // namespace cwg231
462 namespace cwg236
{ // cwg236: 3.2
464 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
465 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
466 } // namespace cwg236
468 namespace cwg237
{ // cwg237: dup 470
469 template<typename T
> struct A
{ void f() { T::error
; } };
470 template<typename T
> struct B
: A
<T
> {};
471 template struct B
<int>; // ok
472 } // namespace cwg237
474 namespace cwg239
{ // cwg239: yes
481 int &g(NS::T
, float);
484 float &r
= g(parm
, 1);
485 extern int &g(NS::T
, float);
488 } // namespace cwg239
492 namespace cwg241
{ // cwg241: yes
495 template <int X
> void f(); // #cwg241-A-f
496 template <int X
> void g(B
);
499 template <class T
> void f(T t
); // #cwg241-C-f
500 template <class T
> void g(T t
); // #cwg241-C-g
504 // expected-error@-1 {{no matching function for call to 'f'}}
505 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
506 // 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}}
508 // 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}}
510 // expected-error@-1 {{no matching function for call to 'f'}}
511 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
514 // expected-error@-1 {{no matching function for call to 'f'}}
515 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
517 // expected-error@-1 {{no matching function for call to 'g'}}
518 // expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
522 // expected-error@-1 {{no matching function for call to 'f'}}
523 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
524 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
527 } // namespace cwg241
529 namespace cwg243
{ // cwg243: yes
535 operator A() = delete; // #cwg243-B
536 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
540 // expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}}
541 // expected-note@#cwg243-A {{candidate constructor}}
542 // expected-note@#cwg243-B {{candidate function has been explicitly deleted}}
543 } // namespace cwg243
545 namespace cwg244
{ // cwg244: 11
546 // NB: this test is reused by cwg399
547 struct B
{}; // #cwg244-B
552 B
* B_ptr
= &D_object
;
556 // expected-error@-1 {{destructor type 'cwg244::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
557 // expected-note@#cwg244-B {{type 'cwg244::B' found by destructor name lookup}}
559 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
562 B_ptr
->B_alias::~B();
563 B_ptr
->B_alias::~B_alias();
565 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
566 B_ptr
->cwg244::~B_alias();
567 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
570 template<typename T
, typename U
>
571 void f(T
*B_ptr
, U D_object
) {
572 D_object
.~B(); // FIXME: Missing diagnostic for this.
574 D_object
.D::~B(); // FIXME: Missing diagnostic for this.
577 B_ptr
->B_alias::~B();
578 B_ptr
->B_alias::~B_alias();
580 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
581 B_ptr
->cwg244::~B_alias();
582 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
584 template void f
<B
, D
>(B
*, D
);
587 template<typename T
> struct E
{};
591 typedef N::F G
; // #cwg244-G
594 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
596 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
598 // This is technically ill-formed; E is looked up in 'N::' and names the
599 // class template, not the injected-class-name of the class. But that's
600 // probably a bug in the standard.
602 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
603 // This is valid; we look up the second F in the same scope in which we
604 // found the first one, that is, 'N::'.
606 // This is technically ill-formed; G is looked up in 'N::' and is not found.
607 // Rejecting this seems correct, but most compilers accept, so we do also.
609 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
610 // expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
613 // Bizarrely, compilers perform lookup in the scope for qualified destructor
614 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
616 namespace QualifiedLookupInScope
{
618 template <typename
> struct S
{ struct Inner
{}; };
620 template <typename U
> void f(typename
N::S
<U
>::Inner
*p
) {
621 typedef typename
N::S
<U
>::Inner T
;
622 p
->::cwg244::QualifiedLookupInScope::N::S
<U
>::Inner::~T();
623 // expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}}
624 // expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}}
626 template void f
<int>(N::S
<int>::Inner
*); // #cwg244-f
628 template <typename U
> void g(U
*p
) {
632 p
->::cwg244::QualifiedLookupInScope::N::S
<int>::Inner::~T();
633 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
635 template void g(N::S
<int>::Inner
*);
637 } // namespace cwg244
639 namespace cwg245
{ // cwg245: yes
641 enum E
{}; // #cwg245-E
643 // expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}}
644 // expected-note@#cwg245-E {{previous use is here}}
646 } // namespace cwg245
648 namespace cwg246
{ // cwg246: 3.2
650 S() try { // #cwg246-try
655 // expected-error@-1 {{cannot jump from this goto statement to its label}}
656 // expected-note@#cwg246-try {{jump bypasses initialization of try block}}
659 } // namespace cwg246
661 namespace cwg247
{ // cwg247: yes
667 void (A::*f
)() = (void (A::*)())&B::f
;
674 void (C::*g
)() = &D::f
;
675 void (D::*h
)() = &D::f
;
684 void (F::*i
)() = &F::f
;
685 } // namespace cwg247
687 namespace cwg248
{ // cwg248: sup P1949
688 int \u040d\u040e = 0;
689 } // namespace cwg248
691 namespace cwg249
{ // cwg249: yes
692 template<typename T
> struct X
{ void f(); };
693 template<typename T
> void X
<T
>::f() {}
694 } // namespace cwg249
696 namespace cwg250
{ // cwg250: yes
697 typedef void (*FPtr
)(double x
[]);
699 template<int I
> void f(double x
[]);
702 template<int I
= 3> void g(double x
[]);
703 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
705 } // namespace cwg250
707 namespace cwg252
{ // cwg252: 3.1
709 void operator delete(void*); // #cwg252-A
712 void operator delete(void*); // #cwg252-B
718 // expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}}
719 // expected-note@#cwg252-A {{member found by ambiguous name lookup}}
720 // expected-note@#cwg252-B {{member found by ambiguous name lookup}}
723 void operator delete(void*, int); // #cwg252-D
727 // expected-error@-1 {{no suitable member 'operator delete' in 'D'}}
728 // expected-note@#cwg252-D {{member 'operator delete' declared here}}
731 void operator delete(void*, int);
732 void operator delete(void*) = delete; // #cwg252-E
733 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
737 // expected-error@-1 {{attempt to use a deleted function}}
738 // expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}}
741 // If both functions are available, the first one is a placement delete.
742 void operator delete(void*, size_t);
743 void operator delete(void*) = delete; // #cwg252-F
744 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
748 // expected-error@-1 {{attempt to use a deleted function}}
749 // expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}}
752 void operator delete(void*, size_t);
756 } // namespace cwg252
758 namespace cwg254
{ // cwg254: 2.9
759 template<typename T
> struct A
{
760 typedef typename
T::type type
; // ok even if this is a typedef-name, because
761 // it's not an elaborated-type-specifier
762 typedef struct T::type foo
;
763 // expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}}
764 // expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}}
765 // expected-note@#cwg254-C {{declared here}}
767 struct B
{ struct type
{}; };
768 struct C
{ typedef struct {} type
; }; // #cwg254-C
770 A
<C
>::type n
; // #cwg254-instantiation
771 } // namespace cwg254
773 namespace cwg255
{ // cwg255: yes
775 void operator delete(void *){};
776 void operator delete(void *, int){};
778 void f(S
*p
) { delete p
; }
779 } // namespace cwg255
783 namespace cwg257
{ // cwg257: 3.4
784 struct A
{ A(int); }; // #cwg257-A
785 struct B
: virtual A
{
787 virtual void f() = 0;
794 // expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}}
795 // expected-note@#cwg257-A {{'cwg257::A' declared here}}
798 } // namespace cwg257
800 namespace cwg258
{ // cwg258: 2.8
803 template<typename
> void g(int);
811 template<int> int &g(int); // #cwg258-B-g
815 int &x
= b
.g
<int>(0);
816 // expected-error@-1 {{no matching member function for call to 'g'}}
817 // expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
819 float &z
= const_cast<const B
&>(b
).h();
822 virtual void f(const int) = 0;
829 virtual void f() = 0; // #cwg258-E-f
834 // expected-error@-1 {{variable type 'struct F' is an abstract class}}
835 // expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}}
836 } // namespace cwg258
838 namespace cwg259
{ // cwg259: 4
839 template<typename T
> struct A
{};
840 template struct A
<int>; // #cwg259-A-int
841 template struct A
<int>;
842 // expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}}
843 // expected-note@#cwg259-A-int {{previous explicit instantiation is here}}
845 template<> struct A
<float>; // #cwg259-A-float
846 template struct A
<float>;
847 // expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}}
848 // expected-note@#cwg259-A-float {{previous template specialization is here}}
850 template struct A
<char>; // #cwg259-A-char
851 template<> struct A
<char>;
852 // expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}}
853 // expected-note@#cwg259-A-char {{explicit instantiation first required here}}
855 template<> struct A
<double>;
856 template<> struct A
<double>;
857 template<> struct A
<double> {}; // #cwg259-A-double
858 template<> struct A
<double> {};
859 // expected-error@-1 {{redefinition of 'A<double>'}}
860 // expected-note@#cwg259-A-double {{previous definition is here}}
862 template<typename T
> struct B
; // #cwg259-B
863 template struct B
<int>;
864 // expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}}
865 // expected-note@#cwg259-B {{template is declared here}}
867 template<> struct B
<float>; // #cwg259-B-float
868 template struct B
<float>;
869 // expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}}
870 // expected-note@#cwg259-B-float {{previous template specialization is here}}
871 } // namespace cwg259
873 // FIXME: When cwg260 is resolved, also add tests for CWG507.
875 namespace cwg261
{ // cwg261: no
876 #pragma clang diagnostic push
877 #pragma clang diagnostic warning "-Wused-but-marked-unused"
879 // FIXME: This is ill-formed, with a diagnostic required, because operator new
880 // and operator delete are inline and odr-used, but not defined in this
882 // We're also missing the -Wused-but-marked-unused diagnostic here.
884 inline void *operator new(size_t) __attribute__((unused
));
885 inline void operator delete(void*) __attribute__((unused
));
889 // FIXME: This is ill-formed, with a required diagnostic, for the same
892 inline void operator delete(void*) __attribute__((unused
));
896 inline void operator delete(void*) __attribute__((unused
));
898 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
902 inline void operator delete(void*) __attribute__((unused
));
904 void h() { C::operator delete(0); }
905 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
907 #pragma clang diagnostic pop
908 } // namespace cwg261
910 namespace cwg262
{ // cwg262: yes
915 } // namespace cwg262
917 namespace cwg263
{ // cwg263: 3.3
920 #if __cplusplus < 201103L
921 friend X::X() throw();
922 friend X::~X() throw();
923 #elif __cplusplus <= 201703L
924 friend constexpr X::X() noexcept
;
927 friend constexpr X::X() noexcept
;
928 friend constexpr X::~X();
931 // expected-error@-1 {{extra qualification on member 'Y'}}
933 // expected-error@-1 {{extra qualification on member '~Y'}}
935 } // namespace cwg263
942 namespace cwg272
{ // cwg272: yes
948 // expected-error@-1 {{invalid argument type 'X' to unary expression}}
951 } // namespace cwg272
955 namespace cwg273
{ // cwg273: yes
966 } // namespace cwg273
970 namespace cwg275
{ // cwg275: no
972 template <class T
> void f(T
) {} // #cwg275-N-f
973 template <class T
> void g(T
) {} // #cwg275-N-g
974 template <> void f(int);
975 template <> void f(char);
976 template <> void f(double);
977 template <> void g(char);
983 template <> void N::f(char) {}
984 // expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}}
985 template <class T
> void g(T
) {}
986 template <> void g(char) {}
987 // FIXME: this should be rejected in c++98 too
988 template void f(long);
989 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
990 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
991 // FIXME: this should be rejected in c++98 too
992 template void N::f(unsigned long);
993 // since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
994 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
995 template void h(long);
996 // expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}}
997 template <> void f(double) {}
998 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1001 template <class T
> void g(T
) {} // #cwg275-g
1003 template <> void N::f(char) {}
1004 template <> void f(int) {}
1005 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1007 // FIXME: this should be rejected in c++98 too
1008 template void f(short);
1009 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
1010 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1011 template void N::f(unsigned short);
1013 // FIXME: this should probably be valid. the wording from the issue
1014 // doesn't clarify this, but it follows from the usual rules.
1015 template void g(int);
1016 // expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}}
1017 // expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}}
1018 // expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}}
1020 // FIXME: likewise, this should also be valid.
1021 template<typename T
> void f(T
) {} // #cwg275-f
1022 template void f(short);
1023 // expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}}
1024 // expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}}
1025 // expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}}
1026 } // namespace cwg275
1030 namespace cwg277
{ // cwg277: 3.1
1033 static_assert(__enable_constant_folding(!intp()), "");
1034 } // namespace cwg277
1036 // cwg279 is in cwg279.cpp
1038 namespace cwg280
{ // cwg280: 2.9
1040 typedef void f1(int);
1041 typedef void f2(int, int);
1042 typedef void f3(int, int, int);
1044 operator f1
*(); // #cwg280-A-f1
1048 operator f0
*(); // #cwg280-B-f0
1050 operator f3
*(); // #cwg280-B-f3
1053 operator f0
*(); // #cwg280-C-f0
1054 operator f1
*(); // #cwg280-C-f1
1055 operator f2
*(); // #cwg280-C-f2
1056 operator f3
*(); // #cwg280-C-f3
1058 struct D
: private A
, B
{ // #cwg280-D
1059 operator f2
*(); // #cwg280-D-f2
1061 struct E
: C
, D
{} e
;
1065 // expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}}
1066 // expected-note@#cwg280-D {{constrained by private inheritance here}}
1067 // expected-note@#cwg280-A-f1 {{member is declared here}}
1068 d(0, 0); // ok, suppressed by member in D
1070 // expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}}
1071 // expected-note@#cwg280-B-f3 {{declared private here}}
1073 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1074 // expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}}
1075 // expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}}
1077 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1078 // expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}}
1079 // expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}}
1081 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1082 // expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1083 // expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1085 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1086 // expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1087 // expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1089 } // namespace cwg280
1091 namespace cwg281
{ // cwg281: no
1099 friend inline void a(); // FIXME: ill-formed
1100 friend inline void b();
1101 friend inline void c(); // FIXME: ill-formed
1102 friend inline void d() {}
1103 friend inline void e() {}
1104 friend inline void f() {}
1106 } // namespace cwg281
1108 namespace cwg283
{ // cwg283: yes
1109 template<typename T
> // #cwg283-template
1112 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1113 // expected-note@#cwg283-template {{template parameter is declared here}}
1115 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1116 // expected-note@#cwg283-template {{template parameter is declared here}}
1118 } // namespace cwg283
1120 namespace cwg284
{ // cwg284: no
1133 // expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}}
1135 struct B::X
{}; // FIXME: ill-formed
1136 enum B::Y e
; // ok per cwg417
1137 class B::Z z
; // ok per cwg417
1151 // expected-error@-1 {{no struct named 'V' in 'cwg284::D'}}
1153 struct D::X
{}; // FIXME: ill-formed
1154 enum D::Y e2
; // ok per cwg417
1155 class D::Z z2
; // ok per cwg417
1156 } // namespace cwg284
1158 namespace cwg285
{ // cwg285: yes
1159 template<typename T
> void f(T
, int); // #cwg285-f-T-int
1160 template<typename T
> void f(int, T
); // #cwg285-f-int-T
1161 template<> void f
<int>(int, int) {}
1162 // 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}}
1163 // expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1164 // expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1165 } // namespace cwg285
1167 namespace cwg286
{ // cwg286: 2.8
1168 template<class T
> struct A
{
1170 template<class T2
> struct B
{}; // #cwg286-B
1176 struct A
<T
>::C::B
<T2
*> { };
1178 A
<short>::C::B
<int*> absip
;
1179 // expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}}
1180 // expected-note@#cwg286-B {{implicitly declared private here}}
1181 } // namespace cwg286
1185 namespace cwg289
{ // cwg289: yes
1186 struct A
; // #cwg289-A
1188 // expected-error@-1 {{base class has incomplete type}}
1189 // expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}}
1191 template<typename T
> struct C
{ typename
T::error error
; };
1192 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1193 // expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}}
1194 struct D
: C
<int> {}; // #cwg289-C-int
1195 } // namespace cwg289
1199 // cwg292 is in cwg292.cpp
1201 namespace cwg294
{ // cwg294: no
1202 void f() throw(int);
1203 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1204 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1206 (void)static_cast<void (*)() throw()>(f
); // FIXME: ill-formed in C++14 and before
1207 // FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}}
1209 // Irony: the above is valid in C++17 and beyond, but that's exactly when
1210 // we reject it. In C++14 and before, this is ill-formed because an
1211 // exception-specification is not permitted in a type-id. In C++17, this is
1212 // valid because it's the inverse of a standard conversion sequence
1213 // containing a function pointer conversion. (Well, it's actually not valid
1214 // yet, as a static_cast is not permitted to reverse a function pointer
1215 // conversion, but that is being changed by core issue).
1216 (void)static_cast<void (*)() throw(int)>(f
); // FIXME: ill-formed in C++14 and before
1217 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1218 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1220 void (*p
)() throw() = f
;
1221 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1222 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}}
1223 void (*q
)() throw(int) = f
;
1224 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1225 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1227 } // namespace cwg294
1229 namespace cwg295
{ // cwg295: 3.7
1232 // expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}
1234 template<typename T
> struct X
{
1241 // expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}
1244 typedef volatile U
*V
;
1245 // expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}
1246 } // namespace cwg295
1248 namespace cwg296
{ // cwg296: yes
1250 static operator int() { return 0; }
1251 // expected-error@-1 {{conversion function must be a non-static member function}}
1253 } // namespace cwg296
1255 namespace cwg298
{ // cwg298: 3.1
1261 typedef A B
; // #cwg298-B
1262 typedef const A C
; // #cwg298-C
1270 // expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}}
1271 // expected-note@#cwg298-B {{declared here}}
1273 // expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}}
1274 // expected-note@#cwg298-C {{declared here}}
1277 // expected-error@-1 {{a type specifier is required for all declarations}}
1280 // expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const cwg298::A') of the class name}}
1282 typedef struct D E
; // #cwg298-E
1284 // expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}}
1285 // expected-note@#cwg298-E {{'E' declared here}}
1292 } // namespace cwg298
1294 namespace cwg299
{ // cwg299: 2.8 c++11
1299 operator int(); // #cwg299-int
1300 operator unsigned short(); // #cwg299-ushort
1302 // FIXME: should this apply to c++98 mode?
1303 int *p
= new int[S()];
1304 // cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}}
1305 int *q
= new int[T()]; // #cwg299-q
1306 // cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}}
1307 // cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}}
1308 // cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}}
1309 // since-cxx14-error-re@#cwg299-q {{{{conversion from 'T' to 'unsigned (long long|long|int)' is ambiguous}}}}
1310 // since-cxx14-note@#cwg299-int {{candidate function}}
1311 // since-cxx14-note@#cwg299-ushort {{candidate function}}
1312 } // namespace cwg299