1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
8 namespace dr1
{ // dr1: no
9 namespace X
{ extern "C" void dr1_f(int a
= 1); }
10 namespace Y
{ extern "C" void dr1_f(int a
= 1); }
11 using X::dr1_f
; using Y::dr1_f
;
14 // FIXME: This should be rejected, due to the ambiguous default argument.
21 // FIXME: This should be rejected, due to the ambiguous default argument.
29 void X::z(int = 1) {} // expected-note {{previous}}
31 void z(int = 1); // expected-error {{redefinition of default argument}}
39 // FIXME: This should be rejected, due to the ambiguous default argument.
46 // FIXME: This should be rejected, due to the ambiguous default argument.
51 namespace dr3
{ // dr3: yes
52 template<typename T
> struct A
{};
53 template<typename T
> void f(T
) { A
<T
> a
; } // expected-note {{implicit instantiation}}
55 template<> struct A
<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}}
58 namespace dr4
{ // dr4: yes
60 static void dr4_f(int) {}
61 static void dr4_f(float) {}
62 void dr4_g(int) {} // expected-note {{previous}}
63 void dr4_g(float) {} // expected-error {{conflicting types}}
67 namespace dr5
{ // dr5: yes
73 const volatile B b
= a
;
77 struct E
{ operator D
&(); } e
;
81 namespace dr7
{ // dr7: yes
82 class A
{ public: ~A(); };
83 class B
: virtual private A
{}; // expected-note 2 {{declared private here}}
84 class C
: public B
{} c
; // expected-error 2 {{inherited virtual base class 'A' has private destructor}} \
85 // expected-note {{implicit default constructor for 'dr7::C' first required here}} \
86 // expected-note {{implicit destructor for 'dr7::C' first required here}}
87 class VeryDerivedC
: public B
, virtual public A
{} vdc
;
89 class X
{ ~X(); }; // expected-note {{here}}
90 class Y
: X
{ ~Y() {} }; // expected-error {{private destructor}}
92 namespace PR16370
{ // This regressed the first time DR7 was fixed.
93 struct S1
{ virtual ~S1(); };
96 struct S4
: virtual S2
{};
105 namespace dr8
{ // dr8: dup 45
108 static const int k
= 5;
110 template<typename
, int, void (A::*)()> struct T
;
114 A::T
<A::U
, A::k
, &A::f
> *A::g() { return 0; }
117 namespace dr9
{ // dr9: yes
120 int m
; // expected-note {{here}}
123 struct N
: protected B
{ // expected-note {{protected}}
126 int R1() { return n
.m
; } // expected-error {{protected member}}
127 int R2() { return n
.m
; }
130 namespace dr10
{ // dr10: dup 45
138 namespace dr11
{ // dr11: yes
139 template<typename T
> struct A
: T
{
143 template<typename T
> struct B
: T
{
145 V v
; // expected-error {{unknown type name}}
147 struct X
{ typedef int U
; };
151 namespace dr12
{ // dr12: sup 239
156 // Under DR12, these call two different functions.
157 // Under DR239, they call the same function.
163 namespace dr13
{ // dr13: no
164 extern "C" void f(int);
167 template<typename T
> struct A
{
170 template<typename T
> int h(void (T
));
172 A
<int> a1(f
); // FIXME: We should reject this.
174 int a3
= h(f
); // FIXME: We should reject this.
178 namespace dr14
{ // dr14: yes
179 namespace X
{ extern "C" int dr14_f(); }
180 namespace Y
{ extern "C" int dr14_f(); }
187 friend int Y::dr14_f();
190 extern "C" int dr14_f() { return c
.k
; }
193 namespace X
{ typedef int T
; typedef int U
; } // expected-note {{candidate}}
194 namespace Y
{ typedef int T
; typedef long U
; } // expected-note {{candidate}}
195 T t
; // ok, same type both times
196 U u
; // expected-error {{ambiguous}}
199 namespace dr15
{ // dr15: yes
200 template<typename T
> void f(int); // expected-note {{previous}}
201 template<typename T
> void f(int = 0); // expected-error {{default arguments cannot be added}}
204 namespace dr16
{ // dr16: yes
205 class A
{ // expected-note {{here}}
206 void f(); // expected-note {{here}}
209 class B
: A
{}; // expected-note 3{{here}}
212 f(); // expected-error {{private member}}
213 A::f(); // expected-error {{private member}} expected-error {{private base}}
218 namespace dr17
{ // dr17: yes
225 int A::f() { return b
.n
; }
227 int g() { return n
; }
233 namespace dr19
{ // dr19: yes
235 int n
; // expected-note {{here}}
237 struct B
: protected A
{ // expected-note {{here}}
241 int get1() { return c
.n
; } // expected-error {{protected member}}
242 int get2() { return ((A
&)c
).n
; } // ok, A is an accessible base of B from here
246 namespace dr20
{ // dr20: yes
251 X(const X
&); // expected-note {{here}}
254 X x
= f(); // expected-error {{private}}
257 namespace dr21
{ // dr21: yes
258 template<typename T
> struct A
;
260 template<typename T
= int> friend struct A
; // expected-error {{default template argument not permitted on a friend template}}
261 template<typename T
= int> friend struct B
; // expected-error {{default template argument not permitted on a friend template}}
265 namespace dr22
{ // dr22: sup 481
266 template<typename dr22_T
= dr22_T
> struct X
; // expected-error {{unknown type name 'dr22_T'}}
268 template<typename T
= T
> struct Y
;
271 namespace dr23
{ // dr23: yes
272 template<typename T
> void f(T
, T
); // expected-note {{candidate}}
273 template<typename T
> void f(T
, int); // expected-note {{candidate}}
274 void g() { f(0, 0); } // expected-error {{ambiguous}}
279 namespace dr25
{ // dr25: yes
281 void f() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
283 void (A::*f
)() throw (int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
284 void (A::*g
)() throw () = f
;
285 #if __cplusplus <= 201402L
286 // expected-error@-2 {{is not superset of source}}
288 // expected-error@-4 {{different exception specifications}}
290 void (A::*g2
)() throw () = 0;
291 void (A::*h
)() throw (int, char) = f
; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
292 void (A::*i
)() throw () = &A::f
;
293 #if __cplusplus <= 201402L
294 // expected-error@-2 {{is not superset of source}}
296 // expected-error@-4 {{different exception specifications}}
298 void (A::*i2
)() throw () = 0;
299 void (A::*j
)() throw (int, char) = &A::f
; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
302 #if __cplusplus <= 201402L
303 // expected-error@-2 {{is not superset of source}}
305 // expected-error@-4 {{different exception specifications}}
309 #if __cplusplus <= 201402L
310 // expected-error@-2 {{is not superset of source}}
312 // expected-error@-4 {{different exception specifications}}
318 namespace dr26
{ // dr26: yes
319 struct A
{ A(A
, const A
& = A()); }; // expected-error {{must pass its first argument by reference}}
322 // FIXME: In C++98, we diagnose this twice.
323 B(const B
&, B
= B());
324 #if __cplusplus <= 201402L
325 // expected-error@-2 1+{{recursive evaluation of default argument}} expected-note@-2 1+{{used here}}
330 C(const C
&, C
= f()); // expected-error {{recursive evaluation of default argument}} expected-note {{used here}}
334 namespace dr27
{ // dr27: yes
341 namespace dr29
{ // dr29: 3.4
342 void dr29_f0(); // expected-note {{here}}
343 void g0() { void dr29_f0(); }
344 extern "C++" void g0_cxx() { void dr29_f0(); }
345 extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
347 extern "C" void dr29_f1(); // expected-note {{here}}
348 void g1() { void dr29_f1(); }
349 extern "C" void g1_c() { void dr29_f1(); }
350 extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
352 void g2() { void dr29_f2(); } // expected-note {{here}}
353 extern "C" void dr29_f2(); // expected-error {{different language linkage}}
355 extern "C" void g3() { void dr29_f3(); } // expected-note {{here}}
356 extern "C++" void dr29_f3(); // expected-error {{different language linkage}}
358 extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}}
359 extern "C" void dr29_f4(); // expected-error {{different language linkage}}
361 extern "C" void g5();
362 extern "C++" void dr29_f5();
364 void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
367 extern "C++" void g6();
368 extern "C" void dr29_f6();
370 void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
373 extern "C" void g7();
374 extern "C++" void dr29_f7(); // expected-note {{here}}
375 extern "C" void g7() {
376 void dr29_f7(); // expected-error {{different language linkage}}
379 extern "C++" void g8();
380 extern "C" void dr29_f8(); // expected-note {{here}}
381 extern "C++" void g8() {
382 void dr29_f8(); // expected-error {{different language linkage}}
386 namespace dr30
{ // dr30: sup 468 c++11
388 template<int> static int f();
390 int x
= A::template f
<0>();
391 int y
= a
.template f
<0>();
392 int z
= p
->template f
<0>();
393 #if __cplusplus < 201103L
394 // FIXME: It's not clear whether DR468 applies to C++98 too.
395 // expected-error@-5 {{'template' keyword outside of a template}}
396 // expected-error@-5 {{'template' keyword outside of a template}}
397 // expected-error@-5 {{'template' keyword outside of a template}}
401 namespace dr31
{ // dr31: yes
404 void operator delete(void*); // expected-note {{here}}
406 // We would call X::operator delete if X() threw (even though it can't,
407 // and even though we allocated the X using ::operator delete).
408 X
*p
= new X
; // expected-error {{private}}
413 namespace dr33
{ // dr33: yes
414 namespace X
{ struct S
; void f(void (*)(S
)); } // expected-note {{candidate}}
415 namespace Y
{ struct T
; void f(void (*)(T
)); } // expected-note {{candidate}}
417 template<typename Z
> Z
g(Y::T
);
418 void h() { f(&g
); } // expected-error {{ambiguous}}
420 template<typename T
> void t(X::S
);
421 template<typename T
, typename U
= void> void u(X::S
); // expected-error 0-1{{default template argument}}
422 void templ() { f(t
<int>); f(u
<int>); }
424 // Even though v<int> cannot select the first overload, ADL considers it
425 // and adds namespace Z to the set of associated namespaces, and then picks
426 // Z::f even though that function has nothing to do with any associated type.
427 namespace Z
{ struct Q
; void f(void(*)()); }
428 template<int> Z::Q
v();
429 template<typename
> void v();
430 void unrelated_templ() { f(v
<int>); }
432 namespace dependent
{
434 template<class T
> struct Y
{
435 friend int operator+(X
, void(*)(Y
)) {}
438 template<typename T
> void f(Y
<T
>);
439 int use
= X() + f
<int>; // expected-error {{invalid operands}}
444 struct Y
{ friend int operator+(Q
, Y (*)()); };
445 struct X
{ template<typename
> static Y
f(); };
446 int m
= Q() + X().f
<int>; // ok
447 int n
= Q() + (&(X().f
<int>)); // ok
454 namespace dr36
{ // dr36: yes
482 struct D
: virtual B
, virtual C
484 using B::i
; // expected-note {{previous using declaration}}
485 using B::i
; // expected-error {{redeclaration of using declaration}}
487 using C::i
; // expected-note {{previous using declaration}}
488 using C::i
; // expected-error {{redeclaration of using declaration}}
490 using B::j
; // expected-note {{previous using declaration}}
491 using B::j
; // expected-error {{redeclaration of using declaration}}
493 using C::j
; // expected-note {{previous using declaration}}
494 using C::j
; // expected-error {{redeclaration of using declaration}}
512 struct D
: virtual B
<T
>, virtual C
<T
>
514 using B
<T
>::i
; // expected-note {{previous using declaration}}
515 using B
<T
>::i
; // expected-error {{redeclaration of using declaration}}
517 using C
<T
>::i
; // expected-note {{previous using declaration}}
518 using C
<T
>::i
; // expected-error {{redeclaration of using declaration}}
520 using B
<T
>::j
; // expected-note {{previous using declaration}}
521 using B
<T
>::j
; // expected-error {{redeclaration of using declaration}}
523 using C
<T
>::j
; // expected-note {{previous using declaration}}
524 using C
<T
>::j
; // expected-error {{redeclaration of using declaration}}
535 using E
<T
>::k
; // expected-note {{previous using declaration}}
536 using E
<T
>::k
; // expected-error {{redeclaration of using declaration}}
543 namespace dr38
{ // dr38: yes
544 template<typename T
> struct X
{};
545 template<typename T
> X
<T
> operator+(X
<T
> a
, X
<T
> b
) { return a
; }
546 template X
<int> operator+<int>(X
<int>, X
<int>);
549 namespace dr39
{ // dr39: no
551 struct A
{ int &f(int); };
561 int &x(int); // expected-note {{found}}
562 static int &y(int); // expected-note {{found}}
567 struct B
: A
, virtual V
{
568 using A::x
; // expected-note {{found}}
570 using A::y
; // expected-note {{found}}
571 static float &y(float);
575 struct C
: A
, B
, virtual V
{} c
; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n struct dr39::example2::C -> A\n struct dr39::example2::C -> B -> A}}
576 int &x
= c
.x(0); // expected-error {{found in multiple base classes}}
577 // FIXME: This is valid, because we find the same static data member either way.
578 int &y
= c
.y(0); // expected-error {{found in multiple base classes}}
583 struct A
{ static int f(); };
584 struct B
: virtual A
{ using A::f
; };
585 struct C
: virtual A
{ using A::f
; };
586 struct D
: B
, C
{} d
;
591 struct A
{ int n
; }; // expected-note {{found}}
594 struct D
: B
, C
{ int f() { return n
; } }; // expected-error {{found in multiple base-class}}
598 // FIXME: This is valid.
599 struct A
{ int n
; }; // expected-note +{{found}}
603 int k
= sizeof(D::n
); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
604 #if __cplusplus >= 201103L
605 decltype(D::n
) n
; // expected-error {{found in multiple base}}
612 namespace dr41
{ // dr41: yes
616 namespace dr42
{ // dr42: yes
617 struct A
{ static const int k
= 0; };
618 struct B
: A
{ static const int k
= A::k
; };
623 namespace dr44
{ // dr44: sup 727
625 template<int> void f();
626 template<> void f
<0>();
630 namespace dr45
{ // dr45: yes
638 namespace dr46
{ // dr46: yes
639 template<typename
> struct A
{ template<typename
> struct B
{}; };
640 template template struct A
<int>::B
<int>; // expected-error {{expected unqualified-id}}
643 namespace dr47
{ // dr47: sup 329
644 template<typename T
> struct A
{
645 friend void f() { T t
; } // expected-error {{redefinition}} expected-note {{previous}}
648 A
<float> b
; // expected-note {{instantiation of}}
654 namespace dr48
{ // dr48: yes
657 static const int m
= 0;
658 static const int n
= 0;
659 static const int o
= 0;
663 // FIXME: We should produce a 'has internal linkage but is not defined'
664 // diagnostic for 'S::n'.
670 namespace dr49
{ // dr49: yes
671 template<int*> struct A
{}; // expected-note 0-2{{here}}
673 #if __has_feature(cxx_constexpr)
676 int *const p
= &k
; // expected-note 0-2{{here}}
679 #if __cplusplus <= 201402L
680 // expected-error@-2 {{must have its address taken}}
682 #if __cplusplus < 201103L
683 // expected-error@-5 {{internal linkage}}
687 #if __cplusplus < 201103L
688 // expected-error@-2 {{must have its address taken}}
690 // expected-error@-4 {{constant expression}}
691 // expected-note@-5 {{read of non-constexpr}}
692 // expected-note@-7 {{declared here}}
696 namespace dr50
{ // dr50: yes
697 struct X
; // expected-note {{forward}}
700 X
*r
= static_cast<X
*>(p
);
701 X
*s
= const_cast<X
*>(p
);
702 X
*t
= reinterpret_cast<X
*>(p
);
703 X
*u
= dynamic_cast<X
*>(p
); // expected-error {{incomplete}}
706 namespace dr51
{ // dr51: yes
716 namespace dr52
{ // dr52: yes
717 struct A
{ int n
; }; // expected-note {{here}}
718 struct B
: private A
{} b
; // expected-note 2{{private}}
719 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
720 int k
= b
.A::n
; // expected-error {{'A' is a private member of 'dr52::A'}}
721 // expected-error@-1 {{cannot cast 'struct B' to its private base}}
724 namespace dr53
{ // dr53: yes
726 enum E
{ e
} x
= static_cast<E
>(n
);
729 namespace dr54
{ // dr54: yes
730 struct A
{ int a
; } a
;
731 struct V
{ int v
; } v
;
732 struct B
: private A
, virtual V
{ int b
; } b
; // expected-note 6{{private here}}
734 A
&sab
= static_cast<A
&>(b
); // expected-error {{private base}}
735 A
*spab
= static_cast<A
*>(&b
); // expected-error {{private base}}
736 int A::*smab
= static_cast<int A::*>(&B::b
); // expected-error {{private base}}
737 B
&sba
= static_cast<B
&>(a
); // expected-error {{private base}}
738 B
*spba
= static_cast<B
*>(&a
); // expected-error {{private base}}
739 int B::*smba
= static_cast<int B::*>(&A::a
); // expected-error {{private base}}
741 V
&svb
= static_cast<V
&>(b
);
742 V
*spvb
= static_cast<V
*>(&b
);
743 int V::*smvb
= static_cast<int V::*>(&B::b
); // expected-error {{virtual base}}
744 B
&sbv
= static_cast<B
&>(v
); // expected-error {{virtual base}}
745 B
*spbv
= static_cast<B
*>(&v
); // expected-error {{virtual base}}
746 int B::*smbv
= static_cast<int B::*>(&V::v
); // expected-error {{virtual base}}
750 int A::*cmab
= (int A::*)(&B::b
);
753 int B::*cmba
= (int B::*)(&A::a
);
757 int V::*cmvb
= (int V::*)(&B::b
); // expected-error {{virtual base}}
758 B
&cbv
= (B
&)(v
); // expected-error {{virtual base}}
759 B
*cpbv
= (B
*)(&v
); // expected-error {{virtual base}}
760 int B::*cmbv
= (int B::*)(&V::v
); // expected-error {{virtual base}}
763 namespace dr55
{ // dr55: yes
765 int test
[(e
+ 1 == 6) ? 1 : -1];
768 namespace dr56
{ // dr56: yes
770 typedef int T
; // expected-note {{previous}}
771 typedef int T
; // expected-error {{redefinition}}
775 typedef X X
; // expected-note {{previous}}
776 typedef X X
; // expected-error {{redefinition}}
780 namespace dr58
{ // dr58: yes
781 // FIXME: Ideally, we should have a CodeGen test for this.
782 #if __cplusplus >= 201103L
783 enum E1
{ E1_0
= 0, E1_1
= 1 };
784 enum E2
{ E2_0
= 0, E2_m1
= -1 };
785 struct X
{ E1 e1
: 1; E2 e2
: 1; };
786 static_assert(X
{E1_1
, E2_m1
}.e1
== 1, "");
787 static_assert(X
{E1_1
, E2_m1
}.e2
== -1, "");
791 namespace dr59
{ // dr59: yes
792 #pragma clang diagnostic push
793 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
794 template<typename T
> struct convert_to
{ operator T() const; };
795 struct A
{}; // expected-note 5+{{candidate}}
796 struct B
: A
{}; // expected-note 0+{{candidate}}
798 A a1
= convert_to
<A
>();
799 A a2
= convert_to
<A
&>();
800 A a3
= convert_to
<const A
>();
801 A a4
= convert_to
<const volatile A
>();
802 #if __cplusplus <= 201402L
803 // expected-error@-2 {{no viable}}
805 A a5
= convert_to
<const volatile A
&>(); // expected-error {{no viable}}
807 B b1
= convert_to
<B
>();
808 B b2
= convert_to
<B
&>();
809 B b3
= convert_to
<const B
>();
810 B b4
= convert_to
<const volatile B
>();
811 #if __cplusplus <= 201402L
812 // expected-error@-2 {{no viable}}
814 B b5
= convert_to
<const volatile B
&>(); // expected-error {{no viable}}
816 A c1
= convert_to
<B
>();
817 A c2
= convert_to
<B
&>();
818 A c3
= convert_to
<const B
>();
819 A c4
= convert_to
<const volatile B
>(); // expected-error {{no viable}}
820 A c5
= convert_to
<const volatile B
&>(); // expected-error {{no viable}}
822 int n1
= convert_to
<int>();
823 int n2
= convert_to
<int&>();
824 int n3
= convert_to
<const int>();
825 int n4
= convert_to
<const volatile int>();
826 int n5
= convert_to
<const volatile int&>();
827 #pragma clang diagnostic pop
830 namespace dr60
{ // dr60: yes
837 namespace dr61
{ // dr61: yes
845 // This is (presumably) valid, because x.f does not refer to an overloaded
848 void (*q
)() = &y
.f
; // expected-error {{cannot create a non-constant pointer to member function}}
849 void (*r
)() = y
.f
; // expected-error {{cannot create a non-constant pointer to member function}}
852 namespace dr62
{ // dr62: yes
856 template<typename T
> struct X
{};
857 template<typename T
> T
get() { return get
<T
>(); }
858 template<typename T
> int take(T
) { return 0; }
863 typedef struct { } *NoNameForLinkagePtr
;
864 #if __cplusplus < 201103L
865 // expected-note@-2 5{{here}}
867 NoNameForLinkagePtr noNameForLinkagePtr
;
870 NoNameForLinkagePtr p
;
873 X
<NoNameForLinkagePtr
> x2
;
874 X
<const NoNameForLinkagePtr
> x3
;
875 NoNameForLinkagePtr p1
= get
<NoNameForLinkagePtr
>();
876 NoNameForLinkagePtr p2
= get
<const NoNameForLinkagePtr
>();
877 int n1
= take(noNameForLinkagePtr
);
878 #if __cplusplus < 201103L
879 // expected-error@-6 {{uses unnamed type}}
880 // expected-error@-6 {{uses unnamed type}}
881 // expected-error@-6 {{uses unnamed type}}
882 // expected-error@-6 {{uses unnamed type}}
883 // expected-error@-6 {{uses unnamed type}}
891 X
<const NoLinkage
> b
;
893 get
<const NoLinkage
>();
894 X
<void (*)(NoLinkage
A::*)> c
;
895 X
<int NoLinkage::*> d
;
896 #if __cplusplus < 201103L
897 // expected-error@-7 {{uses local type}}
898 // expected-error@-7 {{uses local type}}
899 // expected-error@-7 {{uses local type}}
900 // expected-error@-7 {{uses local type}}
901 // expected-error@-7 {{uses local type}}
902 // expected-error@-7 {{uses local type}}
907 namespace dr63
{ // dr63: yes
908 template<typename T
> struct S
{ typename
T::error e
; };
913 namespace dr64
{ // dr64: yes
914 template<class T
> void f(T
);
915 template<class T
> void f(T
*);
916 template<> void f(int*);
917 template<> void f
<int>(int*);
918 template<> void f(int);
923 namespace dr66
{ // dr66: no
925 int f(int n
); // expected-note 2{{candidate}}
932 // FIXME: The first two calls here should be accepted.
933 int a
= f(); // expected-error {{no matching function}}
935 int c
= f(1, 2); // expected-error {{no matching function}}
940 namespace dr68
{ // dr68: yes
941 template<typename T
> struct X
{};
942 struct ::dr68::X
<int> x1
;
943 struct ::dr68::template X
<int> x2
;
944 #if __cplusplus < 201103L
945 // expected-error@-2 {{'template' keyword outside of a template}}
948 friend struct X
<int>;
949 friend struct ::dr68::X
<char>;
950 friend struct ::dr68::template X
<double>;
951 #if __cplusplus < 201103L
952 // expected-error@-2 {{'template' keyword outside of a template}}
957 friend struct ::dr68::template X
<double>;
958 friend typename ::dr68::X
<double>;
959 #if __cplusplus < 201103L
960 // expected-error@-2 {{C++11 extension}}
965 namespace dr69
{ // dr69: yes
966 template<typename T
> static void f() {} // #dr69-f
967 // FIXME: Should we warn here?
968 inline void g() { f
<int>(); }
969 extern template void f
<char>(); // expected-error {{explicit instantiation declaration of 'f' with internal linkage}}
970 #if __cplusplus < 201103L
971 // expected-error@-2 {{C++11 extension}}
973 template<void(*)()> struct Q
{};
975 #if __cplusplus < 201103L
976 // expected-error@-2 {{internal linkage}} expected-note@#dr69-f {{here}}
980 namespace dr70
{ // dr70: yes
981 template<int> struct A
{};
982 template<int I
, int J
> int f(int (&)[I
+ J
], A
<I
>, A
<J
>);
984 int k
= f(arr
, A
<3>(), A
<4>());
990 #if __cplusplus >= 201103L
991 namespace dr73
{ // dr73: sup 1652
993 static_assert(&a
+ 1 != &b
, ""); // expected-error {{not an integral constant expression}}
994 // expected-note@-1 {{comparison against pointer '&a + 1' that points past the end of a complete object}}
998 namespace dr74
{ // dr74: yes
1000 int (*p
)[k
] = new int[k
][k
];
1003 namespace dr75
{ // dr75: yes
1005 static int n
= 0; // expected-error {{non-const}}
1009 namespace dr76
{ // dr76: yes
1010 const volatile int n
= 1;
1011 int arr
[n
]; // expected-error +{{variable length array}} expected-note {{read of volatile}}
1014 namespace dr77
{ // dr77: yes
1021 namespace dr78
{ // dr78: sup ????
1022 // Under DR78, this is valid, because 'k' has static storage duration, so is
1023 // zero-initialized.
1024 const int k
; // expected-error {{default initialization of an object of const}}
1029 namespace dr80
{ // dr80: yes
1034 static int B
; // expected-error {{same name as its class}}
1037 int C
; // expected-error {{same name as its class}}
1042 int D
; // expected-error {{same name as its class}}
1049 namespace dr83
{ // dr83: yes
1050 int &f(const char*);
1055 namespace dr84
{ // dr84: yes
1057 struct A
{ operator B() const; };
1060 B(B
&); // expected-note 0-1{{candidate}}
1061 B(C
); // expected-note 0-1{{no known conversion from 'B' to 'C'}}
1065 // Cannot use B(C) / operator C() pair to construct the B from the B temporary
1066 // here. In C++17, we initialize the B object directly using 'A::operator B()'.
1068 #if __cplusplus <= 201402L
1069 // expected-error@-2 {{no viable}}
1073 namespace dr85
{ // dr85: yes
1076 struct B
{}; // expected-note{{previous declaration is here}}
1077 struct B
; // expected-error{{class member cannot be redeclared}}
1080 union U
{}; // expected-note{{previous declaration is here}}
1081 union U
; // expected-error{{class member cannot be redeclared}}
1083 #if __cplusplus >= 201103L
1085 enum E1
: int { e1
}; // expected-note{{previous declaration is here}}
1086 enum E1
: int; // expected-error{{class member cannot be redeclared}}
1089 enum class E2
{ e2
}; // expected-note{{previous declaration is here}}
1090 enum class E2
; // expected-error{{class member cannot be redeclared}}
1094 template <typename T
>
1096 struct B
{}; // expected-note{{previous declaration is here}}
1097 struct B
; // expected-error{{class member cannot be redeclared}}
1103 namespace dr87
{ // dr87: no
1104 // FIXME: Superseded by dr1975
1105 template<typename T
> struct X
{};
1106 // FIXME: This is invalid.
1107 X
<void() throw()> x
;
1108 // This is valid under dr87 but not under dr1975.
1109 X
<void(void() throw())> y
;
1112 namespace dr88
{ // dr88: yes
1113 template<typename T
> struct S
{
1114 static const int a
= 1; // expected-note {{previous}}
1117 template<> const int S
<int>::a
= 4; // expected-error {{already has an initializer}}
1118 template<> const int S
<int>::b
= 4;
1123 namespace dr90
{ // dr90: yes
1125 template<typename T
> friend void dr90_f(T
);
1128 template<typename T
> friend void dr90_g(T
);
1138 dr90_f(B::C()); // expected-error {{undeclared identifier}}
1139 dr90_f(B::D()); // expected-error {{undeclared identifier}}
1141 dr90_f(F()); // expected-error {{undeclared identifier}}
1143 dr90_g(A()); // expected-error {{undeclared identifier}}
1148 dr90_g(F()); // expected-error {{undeclared identifier}}
1152 namespace dr91
{ // dr91: yes
1153 union U
{ friend int f(U
); };
1157 namespace dr92
{ // dr92: 4 c++17
1158 void f() throw(int, float); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1159 void (*p
)() throw(int) = &f
; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1160 #if __cplusplus <= 201402L
1161 // expected-error@-2 {{target exception specification is not superset of source}}
1163 // expected-warning@-4 {{target exception specification is not superset of source}}
1165 void (*q
)() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1166 void (**pp
)() throw() = &q
;
1167 #if __cplusplus <= 201402L
1168 // expected-error@-2 {{exception specifications are not allowed}}
1170 // expected-error@-4 {{cannot initialize}}
1173 void g(void() throw()); // expected-note 0-2 {{no known conversion}} expected-warning 0-1{{mangled name of 'g' will change in C++17}}
1175 g(f
); // expected-error-re {{{{is not superset|no matching function}}}}
1176 g(q
); // expected-error-re {{{{is not superset|no matching function}}}}
1179 // Prior to C++17, this is OK because the exception specification is not
1180 // considered in this context. In C++17, we *do* perform an implicit
1181 // conversion (which performs initialization), and the exception specification
1182 // is part of the type of the parameter, so this is invalid.
1183 template<void() throw()> struct X
{};
1185 #if __cplusplus > 201402L
1186 // expected-error@-2 {{not implicitly convertible}}
1189 template<void() throw(int)> struct Y
{}; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1195 namespace dr94
{ // dr94: yes
1196 struct A
{ static const int n
= 5; };
1200 namespace dr95
{ // dr95: yes
1207 static void f(); // expected-note {{here}}
1209 struct A
*p
; // dr95::A, not dr95::N::A.
1211 A
*q
= N::p
; // ok, same type
1212 struct B
{ void f() { N::C::f(); } }; // expected-error {{private}}
1215 namespace dr96
{ // dr96: no
1218 template<typename T
> int f(T
);
1219 template<typename T
> struct S
{};
1221 template<template<typename
> class X
> struct B
{};
1223 template<typename T
>
1225 int k1
= a
.template f
<int>(0);
1226 // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1227 // name a class template.
1228 // FIXME: What about alias templates?
1229 int k2
= a
.template f(1);
1230 A::template S
<int> s
;
1235 namespace dr97
{ // dr97: yes
1237 static const int a
= false;
1238 static const int b
= !a
;
1242 namespace dr98
{ // dr98: yes
1245 try { // expected-note 2{{bypasses}}
1246 case 0: // expected-error {{cannot jump}}
1249 } catch (...) { // expected-note 2{{bypasses}}
1250 case 1: // expected-error {{cannot jump}}
1255 goto x
; // expected-error {{cannot jump}}
1257 goto y
; // expected-error {{cannot jump}}
1262 namespace dr99
{ // dr99: sup 214
1263 template<typename T
> void f(T
&);
1264 template<typename T
> int &f(const T
&);