1 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98-17,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++23 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2c %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
9 #if __cplusplus == 199711L
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11 // cxx98-error@-1 {{variadic macros are a C99 feature}}
14 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
15 __extension__
typedef __SIZE_TYPE__
size_t;
17 namespace std
{ struct type_info
; }
19 namespace cwg400
{ // cwg400: yes
20 struct A
{ int a
; struct a
{}; }; // #cwg400-A
21 struct B
{ int a
; struct a
{}; }; // #cwg400-B
22 struct C
: A
, B
{ using A::a
; struct a b
; };
25 // FIXME: we should issue a single diagnostic
26 using B::a
; // #cwg400-using-B-a
27 // expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}}
28 // expected-note@#cwg400-B {{target of using declaration}}
29 // expected-note@#cwg400-A {{conflicting declaration}}
30 // expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}}
31 // expected-note@#cwg400-B {{target of using declaration}}
32 // expected-note@#cwg400-A {{conflicting declaration}}
35 struct E
: A
, B
{ struct a b
; };
36 // expected-error@-1 {{member 'a' found in multiple base classes of different types}}
37 // expected-note@#cwg400-A {{member type 'cwg400::A::a' found by ambiguous name lookup}}
38 // expected-note@#cwg400-B {{member type 'cwg400::B::a' found by ambiguous name lookup}}
41 namespace cwg401
{ // cwg401: 2.8
42 template<class T
, class U
= typename
T::type
> class A
: public T
{}; // #cwg401-A
43 // expected-error@#cwg401-A {{'type' is a private member of 'cwg401::C'}}
44 // expected-note@#cwg402-friend-A-C {{in instantiation of default argument for 'A<C>' required here}}
45 // expected-note@#cwg402-C-type {{implicitly declared private here}}
46 // expected-error@#cwg401-A {{'type' is a protected member of 'cwg401::B'}}
47 // expected-note@#cwg402-b {{in instantiation of default argument for 'A<B>' required here}}
48 // expected-note@#cwg402-B-type {{declared protected here}}
49 // expected-error@#cwg401-A {{'type' is a private member of 'cwg401::D'}}
50 // expected-note@#cwg402-d {{in instantiation of default argument for 'A<D>' required here}}
51 // expected-note@#cwg402-D-type {{implicitly declared private here}}
54 typedef int type
; // #cwg402-B-type
58 typedef int type
; // #cwg402-C-type
59 friend class A
<C
>; // #cwg402-friend-A-C
63 typedef int type
; // #cwg402-D-type
64 friend class A
<D
, int>;
71 template<class T
, class U
= typename
T::type
> class A
: public T
{};
77 E::A
<F
> eaf
; // ok, default argument is in befriended context
79 // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
80 // to not treat the default template argument as a SFINAE context in C++98.
81 template<class T
, class U
= typename
T::type
> void f(T
) {} // #cwg402-f
82 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
83 // cxx98-error@-2 {{'type' is a protected member of 'cwg401::B'}}
84 // cxx98-note@-3 {{in instantiation of default argument for 'f<B>' required here}}
85 // cxx98-note@#cwg402-f-b {{while substituting deduced template arguments into function template 'f' [with T = B, U = (no value)]}}
86 // cxx98-note@#cwg402-B-type {{declared protected here}}
87 void g(B b
) { f(b
); } // #cwg402-f-b
88 // since-cxx11-error@-1 {{no matching function for call to 'f'}}
89 // since-cxx11-note@#cwg402-f {{candidate template ignored: substitution failure [with T = B, U = typename B::type]: 'type' is a protected member of 'cwg401::B'}}
92 namespace cwg403
{ // cwg403: yes
97 template<typename T
> struct X
{};
98 typedef struct X
<A::S
>::X XS
;
100 int k
= f(p
); // ok, finds A::f, even though type XS is a typedef-name
101 // referring to an elaborated-type-specifier naming a
102 // injected-class-name, which is about as far from a
103 // template-id as we can make it.
107 // (NB: also sup 594)
109 namespace cwg405
{ // cwg405: yes
122 void test1(A::S as
) { f(as
); }
123 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
124 void test2(A::S as
) { void f(); f(as
); }
125 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
126 // expected-note@-2 {{'f' declared here}}
127 void test3(A::S as
) { using A::f
; f(as
); } // ok
128 void test4(A::S as
) { using B::f
; f(as
); } // ok
129 void test5(A::S as
) { int f
; f(as
); }
130 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
131 void test6(A::S as
) { struct f
{}; (void) f(as
); }
132 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
133 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
134 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
135 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
140 struct X
{ void operator()(S
); } f
;
142 void testD(D::S ds
) { f(ds
); }
143 // expected-error@-1 {{use of undeclared identifier 'f'}}
149 void testE(E::S es
) { f(es
); }
150 // expected-error@-1 {{use of undeclared identifier 'f'}}
153 namespace cwg406
{ // cwg406: 2.9
156 // expected-error@-1 {{static data member 'n' not allowed in anonymous struct}}
160 // expected-error@-1 {{static data member 'n' not allowed in anonymous union}}
164 namespace cwg407
{ // cwg407: 3.8
165 // NB: reused by cwg1894 and cwg2199
171 typedef struct S S
; // #cwg407-typedef-S
173 // expected-error@-1 {{typedef 'S' cannot be referenced with the 'struct' specifier}}
174 // expected-note@#cwg407-typedef-S {{declared here}}
181 struct S
{}; // #cwg407-A-S
184 typedef int S
; // #cwg407-B-S
190 // expected-error@-1 {{ambiguous}}
191 // expected-note@#cwg407-A-S {{candidate found by name lookup is 'cwg407::UsingDir::A::S'}}
192 // expected-note@#cwg407-B-S {{candidate found by name lookup is 'cwg407::UsingDir::B::S'}}
200 // The standard doesn't say whether this is valid. We interpret
201 // CWG407 as meaning "if lookup finds both a tag and a typedef with the
202 // same type, then it's OK in an elaborated-type-specifier".
210 // The standard doesn't say what to do in these cases either.
224 namespace cwg408
{ // cwg408: 3.4
225 template<int N
> void g() { static_assert(N
!= 1, ""); }
226 template<> void g
<2>() { }
228 template<typename T
> struct S
{
232 template<typename T
> int S
<T
>::i
[] = { 1 };
234 template<typename T
> void S
<T
>::f() {
235 g
<sizeof (i
) / sizeof (int)>();
237 template<> int S
<int>::i
[] = { 1, 2 };
238 template void S
<int>::f(); // uses g<2>(), not g<1>().
241 template<typename T
> struct R
{
245 template<typename T
> int R
<T
>::arr
[1];
246 template<typename T
> void R
<T
>::f() {
247 static_assert(sizeof(arr
) != sizeof(int), "");
249 template<> int R
<int>::arr
[2];
250 template void R
<int>::f();
253 namespace cwg409
{ // cwg409: yes
254 template<typename T
> struct A
{
260 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B; implicit 'typename' is a C++20 extension}}
264 namespace cwg410
{ // cwg410: no
265 template<class T
> void f(T
);
268 template<class T
> void h(T
);
269 template<class T
> void i(T
);
271 friend void f
<>(int);
272 friend void h
<>(int);
274 template<class T
> void i(T
);
275 friend void i
<>(int);
277 static void z(); // #cwg410-z
280 template<> void h(int) { A::z(); }
281 // FIXME: This should be ill-formed. The member A::i<> is befriended,
282 // not this function.
283 template<> void i(int) { A::z(); }
285 template<> void f(int) { M::A::z(); }
286 void g(int) { M::A::z(); }
287 // expected-error@-1 {{'z' is a private member of 'cwg410::M::A'}}
288 // expected-note@#cwg410-z {{declared private here}}
291 // cwg412 is in cwg412.cpp
293 namespace cwg413
{ // cwg413: yes
300 // expected-error@-1 {{excess elements in struct initializer}}
303 struct T
{ // #cwg413-T
310 // expected-error@-1 {{initializer for aggregate with no elements requires explicit braces}}
311 // expected-note@#cwg413-T {{'cwg413::T' declared here}}
314 namespace cwg414
{ // cwg414: dup 305
323 namespace cwg415
{ // cwg415: yes
324 template<typename T
> void f(T
, ...) { T::error
; }
326 void g() { f(0, 0); } // ok
329 namespace cwg416
{ // cwg416: yes
331 int &operator+(const A
&, const A
&);
333 struct A
{ float &operator+(A
&); };
337 namespace cwg417
{ // cwg417: no
340 // expected-warning@-1 {{extra qualification on member 'A'}}
341 struct B
{ struct X
; };
344 // expected-error@-1 {{no struct named 'X' in 'cwg417::C'}}
345 struct B::X
{ struct Y
; };
346 struct C::X::Y
{}; // ok!
353 // FIXME: This is ill-formed.
356 // expected-warning@-1 {{extra qualification on member 'D'}}
359 // expected-error@-1 {{no struct named 'E' in namespace 'cwg417'}}
360 // expected-warning@-2 {{extra qualification on member 'E'}}
366 // expected-error@-1 {{cannot define or redeclare 'G' here because namespace 'M' does not enclose namespace 'cwg417'}}
368 // expected-error@-1 {{cannot define or redeclare 'H' here because namespace 'M' does not enclose namespace 'cwg417'}}
372 namespace cwg418
{ // cwg418: no
374 void f1(int, int = 0);
375 void f1(int = 0, int);
378 } // namespace example1
382 void f2(int); // #cwg418-f2
393 // expected-error@-1 {{no matching function for call to 'f2'}}
394 // expected-note@#cwg418-f2 {{candidate function not viable: requires 1 argument, but 0 were provided}}
396 } // namespace example2
398 // example from [over.match.best]/4
401 extern "C" void f(int = 5);
404 extern "C" void f(int = 5);
412 f(); // FIXME: this should fail
414 } // namespace example3
415 } // namespace cwg418
417 namespace cwg420
{ // cwg420: 9
418 template<typename T
> struct ptr
{
419 T
*operator->() const;
420 T
&operator*() const;
422 template<typename T
, typename P
> void test(P p
) {
429 template void test
<int>(int*);
430 template void test
<int>(ptr
<int>);
431 template void test
<X
>(X
*);
432 template void test
<X
>(ptr
<X
>);
436 p
->template Y
<int>::~Y
<int>();
438 p
->template ~Y
<int>();
439 // expected-error@-1 {{'template' keyword not permitted in destructor name}}
441 template<typename T
> struct Y
{};
442 template void test2(Y
<int>*);
443 template void test2(ptr
<Y
<int> >);
445 void test3(int *p
, ptr
<int> q
) {
453 #if __cplusplus >= 201103L
454 template<typename T
> using id
= T
;
455 struct A
{ template<typename T
> using id
= T
; };
456 void test4(int *p
, ptr
<int> q
) {
459 p
->id
<int>::~id
<int>();
460 q
->id
<int>::~id
<int>();
461 p
->template id
<int>::~id
<int>(); // OK since cwg2292
462 q
->template id
<int>::~id
<int>(); // OK since cwg2292
463 p
->A::template id
<int>::~id
<int>();
464 q
->A::template id
<int>::~id
<int>();
469 namespace cwg421
{ // cwg421: yes
470 struct X
{ X(); int n
; int &r
; };
472 // cxx98-error@-1 {{taking the address of a temporary object of type 'int'}}
473 // since-cxx11-error@-2 {{cannot take the address of an rvalue of type 'int'}}
477 namespace cwg422
{ // cwg422: yes
478 template<typename T
, typename U
> void f() {
479 typedef T type
; // #cwg422-typedef-T
481 // expected-error@-1 {{typedef redefinition with different types ('char' vs 'int')}}
482 // expected-note@#cwg422-f-int-char {{in instantiation of function template specialization 'cwg422::f<int, char>' requested here}}
483 // expected-note@#cwg422-typedef-T {{previous definition is here}}
485 template void f
<int, int>();
486 template void f
<int, char>(); // #cwg422-f-int-char
489 namespace cwg423
{ // cwg423: yes
490 template<typename T
> struct X
{ operator T
&(); };
491 void f(X
<int> x
) { x
+= 1; }
494 namespace cwg424
{ // cwg424: yes
496 typedef int N
; // #cwg424-N
498 // expected-error@-1 {{redefinition of 'N'}}
499 // expected-note@#cwg424-N {{previous definition is here}}
502 typedef X X
; // #cwg424-X
510 // expected-error@-1 {{redefinition of 'X'}}
511 // expected-note@#cwg424-X {{previous definition is here}}
517 typedef int M
; // #cwg424-M
519 // expected-error@-1 {{redefinition of 'M'}}
520 // expected-note@#cwg424-M {{previous definition is here}}
524 namespace cwg425
{ // cwg425: yes
525 struct A
{ template<typename T
> operator T() const; } a
;
527 // expected-error@-1 {{use of overloaded operator '*' is ambiguous (with operand types 'float' and 'struct A')}}
528 // expected-note@-2 +{{built-in candidate}}
530 template<typename T
> struct is_float
;
531 template<> struct is_float
<float> { typedef void type
; };
534 template<typename T
, typename U
= typename is_float
<T
>::type
> operator T() const;
535 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
537 float g
= 1.0f
* b
; // ok
540 namespace cwg427
{ // cwg427: yes
542 struct D
: public B
{
543 D(B
&) = delete; // #cwg427-D
544 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
549 const D
&d2
= static_cast<const D
&>(b
);
550 const D
&d3
= (const D
&)b
;
552 // expected-error@-1 {{conversion function from 'B' to 'const D' invokes a deleted function}}
553 // expected-note@#cwg427-D {{'D' has been explicitly marked deleted here}}
556 namespace cwg428
{ // cwg428: yes
557 template<typename T
> T
make();
558 extern struct X x
; // #cwg428-X
561 // expected-error@-1 {{cannot throw}}
563 throw make
<const volatile void*>();
565 // expected-error@-1 {{cannot throw}}
566 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
568 // expected-error@-1 {{cannot throw}}
569 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
571 // expected-error@-1 {{cannot throw}}
572 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
573 throw make
<const volatile X
&>();
574 // expected-error@-1 {{cannot throw}}
575 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
576 throw make
<const volatile X
*>();
577 // expected-error@-1 {{cannot throw}}
578 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
582 namespace cwg429
{ // cwg429: 2.8 c++11
583 // FIXME: This rule is obviously intended to apply to C++98 as well.
585 static void *operator new(size_t, size_t);
586 static void operator delete(void*, size_t); // #cwg429-delete
588 // since-cxx11-error@-1 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
589 // since-cxx11-note@#cwg429-delete {{here}}
591 static void *operator new(size_t, size_t);
592 static void operator delete(void*);
593 static void operator delete(void*, size_t);
594 } *b
= new (0) B
; // ok, second delete is not a non-placement deallocation function
597 namespace cwg430
{ // cwg430: yes c++11
599 // FIXME: This should apply in C++98 too.
601 int a
[] = { n
++, n
++, n
++ };
602 // cxx98-warning@-1 {{multiple unsequenced modifications to 'n'}}
606 namespace cwg431
{ // cwg431: yes
608 template<typename T
> T
*get();
609 template<typename T
> struct B
{
610 template<typename U
> U
*get();
614 template<typename T
> void f(A a
) {
615 a
.get
<A
>()->get
<T
>();
618 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
619 a
.get
<T
>()->template get
<T
>();
621 A::B
<int> *b
= a
.get
<A::B
<int> >();
623 b
->A::B
<int>::get
<int>();
624 b
->A::B
<int>::get
<T
>();
625 b
->A::B
<T
>::get
<int>();
626 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
627 b
->A::B
<T
>::template get
<int>();
628 b
->A::B
<T
>::get
<T
>();
629 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
630 b
->A::B
<T
>::template get
<T
>();
631 A::B
<T
> *c
= a
.get
<A::B
<T
> >();
633 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
634 c
->template get
<int>();
638 namespace cwg432
{ // cwg432: 3.0
639 template<typename T
> struct A
{};
640 template<typename T
> struct B
: A
<B
> {};
641 // expected-error@-1 {{use of class template 'B' requires template arguments}}
642 // expected-note@-2 {{template is declared here}}
643 template<typename T
> struct C
: A
<C
<T
> > {};
644 #if __cplusplus >= 201103L
645 template<typename T
> struct D
: decltype(A
<D
>()) {};
646 // since-cxx11-error@-1 {{use of class template 'D' requires template arguments}}
647 // since-cxx11-note@-2 {{template is declared here}}
651 namespace cwg433
{ // cwg433: yes
652 template<class T
> struct S
{
656 template<class T
> void S
<T
>::f(union U
*) {}
661 namespace cwg434
{ // cwg434: sup 2352
665 const int *&rpci
= pi
;
666 // expected-error@-1 {{binding reference of type 'const int *' to value of type 'int *' not permitted due to incompatible qualifiers}}
667 const int * const &rcpci
= pi
; // OK
672 #if __cplusplus >= 201103L
674 const int * const &rcpci
= pi
;
675 static_assert(&rcpci
== &pi
, "");
681 namespace cwg436
{ // cwg436: yes
682 enum E
{ f
}; // #cwg436-f
684 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}
685 // expected-note@#cwg436-f {{previous definition is here}}
688 namespace cwg437
{ // cwg437: sup 1308
689 // This is superseded by 1308, which is in turn superseded by 1330,
690 // which restores this rule.
691 template<typename U
> struct T
: U
{};
694 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
695 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
696 void g() throw(T
<S
>);
697 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
698 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
701 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
702 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
707 // cwg438 is in cwg438.cpp
708 // cwg439 is in cwg439.cpp
709 // cwg441 is in cwg441.cpp
713 namespace cwg444
{ // cwg444: yes
715 struct B
{ // #cwg444-B
716 D
&operator=(D
&) = delete; // #cwg444-deleted
717 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
719 struct D
: B
{ // #cwg444-D
724 // expected-error@-1 {{overload resolution selected deleted operator '='}}
725 // expected-note@#cwg444-deleted {{candidate function has been explicitly deleted}}
726 // expected-note@#cwg444-D {{candidate function (the implicit copy assignment operator)}}
727 // expected-note@#cwg444-B {{candidate function (the implicit copy assignment operator)}}
728 // since-cxx11-note@#cwg444-B {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}}
729 // since-cxx11-note@#cwg444-D {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}}
733 namespace cwg445
{ // cwg445: 3.2
734 class A
{ void f(); }; // #cwg445-f
737 // expected-error@-1 {{friend function 'f' is a private member of 'cwg445::A'}}
738 // expected-note@#cwg445-f {{implicitly declared private here}}
742 namespace cwg446
{ // cwg446: 2.8
746 A(const A
&) = delete; // #cwg446-deleted
747 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
751 void f(A a
, bool b
, C c
) {
754 // expected-error@-1 {{call to deleted constructor of 'A'}}
755 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
757 // expected-error@-1 {{call to deleted constructor of 'A'}}
758 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
760 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
761 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
765 // expected-error@-1 {{call to deleted constructor of 'A'}}
766 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
768 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
769 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
771 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
772 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
776 namespace cwg447
{ // cwg447: yes
777 struct A
{ int n
; int a
[4]; };
778 template<int> struct U
{
780 template<typename V
> static void h();
782 template<typename T
> U
<sizeof(T
)> g(T
);
783 template<typename T
, int N
> void f(int n
) {
784 // ok, not type dependent
785 g(__builtin_offsetof(A
, n
)).h
<int>();
786 g(__builtin_offsetof(T
, n
)).h
<int>();
787 // value dependent if first argument is a dependent type
788 U
<__builtin_offsetof(A
, n
)>::type a
;
789 // FIXME: instead of ";", we should be suggesting "typename"
790 U
<__builtin_offsetof(T
, n
)>::type b
;
791 // expected-error@-1 {{expected ';' after expression}}
792 // expected-error@-2 {{use of undeclared identifier 'b'}}
793 // as an extension, we allow the member-designator to include array indices
794 g(__builtin_offsetof(A
, a
[0])).h
<int>();
795 g(__builtin_offsetof(A
, a
[N
])).h
<int>();
796 U
<__builtin_offsetof(A
, a
[0])>::type c
;
797 // FIXME: instead of ";", we should be suggesting "typename"
798 U
<__builtin_offsetof(A
, a
[N
])>::type d
;
799 // expected-error@-1 {{expected ';' after expression}}
800 // expected-error@-2 {{use of undeclared identifier 'd'}}
804 namespace cwg448
{ // cwg448: 2.8
805 template<typename T
= int> void f(int); // #cwg448-f-int
806 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
807 template<typename T
> void g(T t
) {
809 // expected-error@-1 {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
810 // expected-note@#cwg448-g {{in instantiation of function template specialization 'cwg448::g<cwg448::HideFromADL::X>' requested here}}
811 // expected-note@#cwg448-f-T {{'f' should be declared prior to the call site or in namespace 'cwg448::HideFromADL'}}
813 // expected-error@-1 {{no matching function for call to 'f'}}
814 // expected-note@#cwg448-f-int {{candidate function template not viable: no known conversion from 'cwg448::HideFromADL::X' to 'int' for 1st argument}}
816 template<typename T
> void f(T
); // #cwg448-f-T
817 namespace HideFromADL
{ struct X
{}; }
818 template void g(int); // ok
819 template void g(HideFromADL::X
); // #cwg448-g
824 namespace cwg450
{ // cwg450: yes
827 void f2(A
&); // #cwg450-f2
832 // expected-error@-1 {{no matching function for call to 'f2'}}}
833 // expected-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}}
835 #if __cplusplus >= 201103L
839 // expected-error@-1 {{no matching function for call to 'f2'}}}
840 // expected-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}}
845 namespace cwg451
{ // cwg451: yes
847 // expected-warning@-1 {{division by zero is undefined}}
848 const int b
= 1 / 0; // #cwg451-b
849 // expected-warning@-1 {{division by zero is undefined}}
850 static_assert(b
, "");
851 // expected-error@-1 {{expression is not an integral constant expression}}
852 // expected-note@-2 {{initializer of 'b' is not a constant expression}}
853 // expected-note@#cwg451-b {{declared here}}
856 namespace cwg452
{ // cwg452: yes
861 A() : a(f()), b(this->f() + a
), c(this->a
), p(this) {}
865 // cwg454 FIXME write a codegen test
867 namespace cwg456
{ // cwg456: yes
871 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
872 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const int'}}
874 const bool f
= false;
876 // cxx98-warning@-1 {{initialization of pointer of type 'void *' to null from a constant boolean}}
877 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const bool'}}
880 namespace cwg457
{ // cwg457: yes
882 const volatile int b
= 1;
883 static_assert(a
, "");
884 static_assert(b
, "");
885 // expected-error@-1 {{expression is not an integral constant expression}}
886 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
891 // expected-error@-1 {{expression is not an integral constant expression}}
892 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
896 namespace cwg458
{ // cwg458: 11
900 template<typename
> int g();
903 template<typename
> struct B
: A
{
905 template<typename
> int g();
906 template<typename
> int h();
912 template<typename T
> // #cwg458-g-T
915 // expected-error@-1 {{'T' does not refer to a value}}
916 // expected-note@#cwg458-g-T {{declared here}}
929 template<typename T
> // #cwg458-h-T
932 // expected-error@-1 {{'T' does not refer to a value}}
933 // expected-note@#cwg458-h-T {{declared here}}
937 namespace cwg460
{ // cwg460: yes
938 namespace X
{ namespace Q
{ int n
; } }
941 // expected-error@-1 {{using declaration requires a qualified name}}
943 // expected-error@-1 {{using declaration cannot refer to a namespace}}
944 // expected-note@-2 {{did you mean 'using namespace'?}}
946 // expected-error@-1 {{using declaration cannot refer to a namespace}}
947 // expected-note@-2 {{did you mean 'using namespace'?}}
952 // cwg462 is in cwg462.cpp
957 namespace cwg466
{ // cwg466: 2.8
959 typedef const int CI
;
960 typedef volatile int VI
;
961 void g(int a
, CI b
, VI c
) {
962 // since-cxx20-warning@-1 {{volatile-qualified parameter type 'VI' (aka 'volatile int') is deprecated}}
970 a
.CI::~VI(); // allowed by changes to [expr.id.prim.qual]/2 introduced in P1131R2
988 namespace cwg467
{ // cwg467: yes
995 static int k
= stuff();
1002 // expected-error@-1 {{cannot jump from this goto statement to its label}}
1003 // expected-note@#cwg467-k {{jump bypasses variable initialization}}
1004 int k
= stuff(); // #cwg467-k
1010 namespace cwg468
{ // cwg468: yes c++11
1011 // FIXME: Should we allow this in C++98 too?
1012 template<typename
> struct A
{
1013 template<typename
> struct B
{
1017 int k
= cwg468::template A
<int>::template B
<char>::C
;
1018 // cxx98-error@-1 {{'template' keyword outside of a template}}
1019 // cxx98-error@-2 {{'template' keyword outside of a template}}
1022 namespace cwg469
{ // cwg469: no
1023 template<typename T
> struct X
; // #cwg469-X
1024 template<typename T
> struct X
<const T
> {};
1026 // expected-error@-1 {{implicit instantiation of undefined template 'cwg469::X<int &>'}}
1027 // expected-note@#cwg469-X {{template is declared here}}
1030 namespace cwg470
{ // cwg470: yes
1031 template<typename T
> struct A
{
1034 template<typename T
> struct C
{
1037 template struct A
<int>; // #cwg470-A-int
1038 template struct A
<int>::B
;
1039 // expected-error@-1 {{duplicate explicit instantiation of 'B'}}
1040 // expected-note@#cwg470-A-int {{previous explicit instantiation is here}}
1042 // ok, instantiating C<char> doesn't instantiate base class members.
1043 template struct A
<char>;
1044 template struct C
<char>;
1047 namespace cwg471
{ // cwg471: 2.8
1048 struct A
{ int n
; };
1049 struct B
: private virtual A
{};
1050 struct C
: protected virtual A
{};
1051 struct D
: B
, C
{ int f() { return n
; } };
1052 struct E
: private virtual A
{
1055 struct F
: E
, B
{ int f() { return n
; } };
1056 struct G
: virtual A
{
1058 using A::n
; // #cwg471-G-using
1060 struct H
: B
, G
{ int f() { return n
; } };
1061 // expected-error@-1 {{'n' is a private member of 'cwg471::G'}}
1062 // expected-note@#cwg471-G-using {{declared private here}}
1065 namespace cwg472
{ // cwg472: no drafting 2011-04
1069 struct I
: protected B
{}; // #cwg472-struct-I
1070 struct D
: public I
{
1073 // expected-error@-1 {{'i' is a protected member of 'cwg472::B'}}
1074 // expected-note@#cwg472-struct-I {{constrained by protected inheritance here}}
1075 // expected-note@#cwg472-i {{member is declared here}}
1082 namespace cwg474
{ // cwg474: 3.4
1089 void g(); // #cwg474-g
1094 // expected-error@-1 {{functions that differ only in their return type cannot be overloaded}}
1095 // expected-note@#cwg474-g {{previous declaration is here}}
1099 // cwg475 FIXME write a libc++abi test
1101 namespace cwg477
{ // cwg477: 3.5
1107 friend explicit A::A();
1108 // expected-error@-1 {{'explicit' is invalid in friend declarations}}
1109 friend virtual void A::f();
1110 // expected-error@-1 {{'virtual' is invalid in friend declarations}}
1113 // expected-error@-1 {{can only be specified inside the class definition}}
1114 virtual void A::f() {}
1115 // expected-error@-1 {{can only be specified inside the class definition}}
1118 namespace cwg478
{ // cwg478: yes
1119 struct A
{ virtual void f() = 0; }; // #cwg478-f
1122 // expected-error@-1 {{array of abstract class type 'A'}}
1123 // expected-note@#cwg478-f {{unimplemented pure virtual method 'f' in 'A'}}
1126 namespace cwg479
{ // cwg479: 2.8
1130 S(const S
&); // #cwg479-S-copy-ctor
1131 ~S(); // #cwg479-S-dtor
1135 // expected-error@-1 {{temporary of type 'S' has private destructor}}
1136 // expected-note@#cwg479-S-dtor {{declared private here}}
1137 // expected-error@-3 {{exception object of type 'S' has private destructor}}
1138 // expected-note@#cwg479-S-dtor {{declared private here}}
1139 // cxx98-error@-5 {{C++98 requires an accessible copy constructor for class 'cwg479::S' when binding a reference to a temporary; was private}}
1140 // cxx98-note@#cwg479-S-copy-ctor {{declared private here}}
1141 // cxx98-14-error@-7 {{calling a private constructor of class 'cwg479::S'}}
1142 // cxx98-14-note@#cwg479-S-copy-ctor {{declared private here}}
1146 // expected-error@-1 {{variable of type 'S' has private destructor}}
1147 // expected-note@#cwg479-S-dtor {{declared private here}}
1149 // expected-error@-1 {{exception object of type 'S' has private destructor}}
1150 // expected-note@#cwg479-S-dtor {{declared private here}}
1151 // expected-error@-3 {{calling a private constructor of class 'cwg479::S'}}
1152 // expected-note@#cwg479-S-copy-ctor {{declared private here}}
1159 // expected-error@-1 {{calling a private constructor of class 'cwg479::S'}}
1160 // expected-note@#cwg479-S-copy-ctor {{declared private here}}
1161 // expected-error@-3 {{variable of type 'S' has private destructor}}
1162 // expected-note@#cwg479-S-dtor {{declared private here}}
1167 namespace cwg480
{ // cwg480: yes
1168 struct A
{ int n
; };
1170 struct C
: virtual B
{};
1175 // expected-error@-1 {{conversion from pointer to member of class 'cwg480::A' to pointer to member of class 'cwg480::D' via virtual base 'cwg480::B' is not allowed}}
1178 int A::*d
= static_cast<int A::*>(c
);
1179 // expected-error@-1 {{conversion from pointer to member of class 'cwg480::D' to pointer to member of class 'cwg480::A' via virtual base 'cwg480::B' is not allowed}}
1183 D
*g
= static_cast<D
*>(f
);
1184 // expected-error@-1 {{cannot cast 'cwg480::A *' to 'D *' via virtual base 'cwg480::B'}}
1188 D
&k
= static_cast<D
&>(j
);
1189 // expected-error@-1 {{cannot cast 'A' to 'D &' via virtual base 'cwg480::B'}}
1192 namespace cwg481
{ // cwg481: 2.8
1193 template<class T
, T U
> class A
{ T
*x
; };
1195 // expected-error@-1 {{unknown type name 'T'}}
1197 template<class T
*U
> class B
{ T
*x
; };
1201 template<class T
> void f(class D
*p
);
1205 template<typename A
= C
, typename C
= A
> struct E
{
1207 typedef ::cwg481::C c
; // #cwg481-c
1209 // expected-error@-1 {{typedef redefinition with different types ('int' vs '::cwg481::C')}}
1210 // expected-note@#cwg481-E-int {{in instantiation of member function 'cwg481::E<int>::f' requested here}}
1211 // expected-note@#cwg481-c {{previous definition is here}}
1214 template struct E
<>; // ok
1215 template struct E
<int>; // #cwg481-E-int
1217 template<template<typename U_no_typo_correction
> class A
,
1219 U_no_typo_correction
*C
>
1220 // expected-error@-1 {{unknown type name 'U_no_typo_correction'}}
1222 U_no_typo_correction
*x
;
1223 // expected-error@-1 {{unknown type name 'U_no_typo_correction'}}
1226 template<template<class H
*> class> struct G
{
1232 template<N X
, typename N
, template<N Y
> class T
> struct I
;
1233 template<char*> struct J
;
1234 I
<123, char*, J
> *j
;
1237 namespace cwg482
{ // cwg482: 3.5
1242 // expected-warning@-1 {{extra qualification on member 'a'}}
1244 // expected-warning@-1 {{extra qualification on member 'f'}}
1246 inline namespace X
{
1247 // cxx98-error@-1 {{inline namespaces are a C++11 feature}}
1253 // expected-warning@-1 {{extra qualification on member 'b'}}
1255 // expected-warning@-1 {{extra qualification on member 'g'}}
1256 struct cwg482::S
{};
1257 // expected-warning@-1 {{extra qualification on member 'S'}}
1260 // expected-warning@-1 {{extra qualification on member 'f'}}
1262 // expected-warning@-1 {{extra qualification on member 'g'}}
1264 // FIXME: The following are valid in CWG482's wording, but these are bugs in
1265 // the wording which we deliberately don't implement.
1266 namespace N
{ typedef int type
; }
1267 typedef int N::type
;
1268 // expected-error@-1 {{typedef declarator cannot be qualified}}
1272 // expected-error@-1 {{extra qualification on member 'B'}}
1274 #if __cplusplus >= 201103L
1277 // expected-error@-1 {{extra qualification on member 'C'}}
1282 namespace cwg483
{ // cwg483: yes
1284 static_assert(__SCHAR_MAX__
>= 127, "");
1285 static_assert(__SHRT_MAX__
>= 32767, "");
1286 static_assert(__INT_MAX__
>= 32767, "");
1287 static_assert(__LONG_MAX__
>= 2147483647, "");
1288 static_assert(__LONG_LONG_MAX__
>= 9223372036854775807, "");
1291 static_assert(__PTRDIFF_WIDTH__
>= 16, "");
1292 static_assert(__SIG_ATOMIC_WIDTH__
>= 8, "");
1293 static_assert(__SIZE_WIDTH__
>= 16, "");
1294 static_assert(__WCHAR_WIDTH__
>= 8, "");
1295 static_assert(__WINT_WIDTH__
>= 16, "");
1299 namespace cwg484
{ // cwg484: yes
1314 void f() { return CA::f(); }
1318 typedef C CT
; // #cwg484-typedef-CT
1320 // expected-error@-1 {{definition of type 'CT' conflicts with typedef of the same name}}
1321 // expected-note@#cwg484-typedef-CT {{'CT' declared here}}
1325 typedef D DT
; // #cwg484-typedef-DT
1328 // expected-error@-1 {{definition of type 'DT' conflicts with typedef of the same name}}
1329 // expected-note@#cwg484-typedef-DT {{'DT' declared here}}
1333 // expected-error@-1 {{a type specifier is required for all declarations}}
1337 namespace cwg485
{ // cwg485: yes
1340 int operator+(S
, S
);
1341 template<typename T
> int f(S
);
1343 template<typename T
> int f();
1346 int a
= operator+(s
, s
);
1350 namespace cwg486
{ // cwg486: yes
1351 template<typename T
> T
f(T
*); // #cwg486-f
1361 // expected-error@-1 {{no matching function for call to 'f'}}
1362 // expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = void ()]: function cannot return function type 'void ()'}}
1364 // expected-error@-1 {{no matching function for call to 'f'}}
1365 // expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = int[10]]: function cannot return array type 'int[10]'}}
1369 namespace cwg487
{ // cwg487: yes
1371 int operator+(int, E
); // #cwg487-operator-plus
1372 static_assert(4 + e
, "");
1373 // expected-error@-1 {{expression is not an integral constant expression}}
1374 // since-cxx11-note@-2 {{non-constexpr function 'operator+' cannot be used in a constant expression}}
1375 // since-cxx11-note@#cwg487-operator-plus {{declared here}}
1378 namespace cwg488
{ // cwg488: yes c++11
1379 template <typename T
> void f(T
);
1382 // FIXME: It seems CWG thought this should be a SFINAE failure prior to
1383 // allowing local types as template arguments. In C++98, we should either
1384 // allow local types as template arguments or treat this as a SFINAE
1388 // cxx98-error@-1 {{template argument uses local type 'E'}}
1394 namespace cwg490
{ // cwg490: 2.8
1395 template<typename T
> struct X
{};
1399 struct K
{}; // #cwg490-k
1404 int X
<T
>::*i(); // #cwg490-i
1407 template<typename T
> T
k();
1417 friend int A::h(X
<T
>);
1419 // FIXME: Per this DR, these two are valid! That is another defect
1420 // (no number yet...) which will eventually supersede this one.
1421 friend int X
<T
>::*A::i();
1422 // expected-error@-1 {{return type of out-of-line definition of 'cwg490::A::i' differs from that in the declaration}}
1423 // expected-note@#cwg490-i {{previous declaration is here}}
1424 friend int K::*A::j();
1425 // expected-error@-1 {{use of undeclared identifier 'K'; did you mean 'A::K'?}}
1426 // expected-note@#cwg490-k {{'A::K' declared here}}
1428 // ok, lookup finds B::T, not A::T, so return type matches
1429 friend char A::k
<T
>();
1430 friend int A::k
<U
>();
1432 // A conversion-type-id in a conversion-function-id is always looked up in
1433 // the class of the conversion function first.
1434 friend A::operator X
<T
>();
1438 namespace cwg491
{ // cwg491: dup 413
1439 struct A
{} a
, b
[3] = { a
, {} };
1440 A c
[2] = { a
, {}, b
[1] };
1441 // expected-error@-1 {{excess elements in array initializer}}
1444 // cwg492 is in cwg492.cpp
1446 namespace cwg493
{ // cwg493: dup 976
1448 template <class T
> operator const T
&() const;
1456 namespace cwg494
{ // cwg494: dup 372
1469 namespace cwg495
{ // cwg495: 3.5
1470 template<typename T
>
1472 operator int() { return T::error
; }
1473 template<typename U
> operator U();
1478 template<typename T
>
1480 template<typename U
> operator U();
1481 operator int() { return T::error
; }
1487 namespace cwg496
{ // cwg496: sup 2094
1488 struct A
{ int n
; };
1489 struct B
{ volatile int n
; };
1490 static_assert(__is_trivially_copyable(const int), "");
1491 // This checks the cwg2094 behavior, not cwg496
1492 static_assert(__is_trivially_copyable(volatile int), "");
1493 static_assert(__is_trivially_constructible(A
, const A
&), "");
1494 static_assert(__is_trivially_constructible(B
, const B
&), "");
1495 static_assert(__is_trivially_assignable(A
, const A
&), "");
1496 static_assert(__is_trivially_assignable(B
, const B
&), "");
1499 namespace cwg497
{ // cwg497: sup 253
1507 // expected-error@-1 {{read-only variable is not assignable}}
1518 // expected-error@-1 {{read-only variable is not assignable}}
1522 namespace cwg499
{ // cwg499: yes
1524 void f() { throw str
; }