1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 namespace dr100
{ // dr100: yes
9 template<const char (*)[4]> struct A
{}; // expected-note 0-1{{declared here}}
10 template<const char (&)[4]> struct B
{}; // expected-note 0-1{{declared here}}
11 template<const char *> struct C
{}; // expected-note 0-1{{declared here}}
12 template<const char &> struct D
{}; // expected-note 0-1{{declared here}}
16 D
<*"quux"> d
; // #100d
17 #if __cplusplus < 201703L
18 // expected-error@#100a {{does not refer to any declaration}}
19 // expected-error@#100b {{does not refer to any declaration}}
20 // expected-error@#100c {{does not refer to any declaration}}
21 // expected-error@#100d {{does not refer to any declaration}}
23 // expected-error@#100a {{pointer to string literal is not allowed in a template argument}}
24 // expected-error@#100b {{reference to string literal is not allowed in a template argument}}
25 // expected-error@#100c {{pointer to subobject of string literal is not allowed in a template argument}}
26 // expected-error@#100d {{reference to subobject of string literal is not allowed in a template argument}}
30 namespace dr101
{ // dr101: 3.5
31 extern "C" void dr101_f();
32 typedef unsigned size_t;
34 extern "C" void dr101_f();
35 typedef unsigned size_t;
39 extern "C" void dr101_f();
40 typedef unsigned size_t;
43 namespace dr102
{ // dr102: yes
45 template<typename T
> T
f(T a
, T b
) { return a
+ b
; } // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
50 B::S
operator+(B::S
, B::S
); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}}
51 template B::S
A::f(B::S
, B::S
); // expected-note {{in instantiation of}}
58 namespace dr106
{ // dr106: sup 540
61 typedef const r1 r1
; // expected-warning {{has no effect}}
62 typedef const r1
&r1
; // expected-warning {{has no effect}}
64 typedef const int &r2
;
66 typedef const r2 r2
; // expected-warning {{has no effect}}
67 typedef const r2
&r2
; // expected-warning {{has no effect}}
70 namespace dr107
{ // dr107: yes
72 extern "C" S
operator+(S
, S
) { return S(); }
75 namespace dr108
{ // dr108: yes
76 template<typename T
> struct A
{
77 struct B
{ typedef int X
; };
79 #if __cplusplus <= 201703L
80 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
82 struct C
: B
{ X x
; }; // expected-error {{unknown type name}}
84 template<> struct A
<int>::B
{ int X
; };
87 namespace dr109
{ // dr109: yes
88 struct A
{ template<typename T
> void f(T
); };
89 template<typename T
> struct B
: T
{
90 using T::template f
; // expected-error {{'template' keyword not permitted here}}
91 using T::template f
<int>; // expected-error {{'template' keyword not permitted here}} expected-error {{using declaration cannot refer to a template specialization}}
92 // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.
93 using T::f
<int>; // expected-error {{use 'template' keyword}} expected-error {{using declaration cannot refer to a template specialization}}
94 void g() { this->f
<int>(123); } // expected-error {{use 'template' keyword}}
98 namespace dr111
{ // dr111: dup 535
99 struct A
{ A(); A(volatile A
&, int = 0); A(A
&, const char * = "foo"); };
100 struct B
: A
{ B(); }; // expected-note +{{would lose const qualifier}} expected-note {{requires 0 arguments}}
102 B
b2(b1
); // expected-error {{no matching constructor}}
105 namespace dr112
{ // dr112: yes
110 volatile T a2
[1] = {};
112 volatile Arr a4
= {};
113 template<const volatile T
*> struct X
{};
118 #if __cplusplus < 201103L
119 // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}}
120 // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}}
122 // FIXME: Test this somehow.
126 namespace dr113
{ // dr113: yes
129 no_such_function(); // expected-error {{undeclared}}
136 namespace dr114
{ // dr114: yes
138 virtual void f(int) = 0; // expected-note {{unimplemented}}
141 template<typename T
> void f(T
);
143 } b
; // expected-error {{abstract}}
146 namespace dr115
{ // dr115: yes
147 template<typename T
> int f(T
); // expected-note +{{}}
148 template<typename T
> int g(T
); // expected-note +{{}}
149 template<typename T
> int g(T
, int); // expected-note +{{}}
151 int k1
= f(&f
); // expected-error {{no match}}
153 int k3
= f(&g
<int>); // expected-error {{no match}}
156 (void)&f
; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}}
158 (void)&g
<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}}
160 &f
; // expected-error {{reference to overloaded function could not be resolved}}
161 &f
<int>; // expected-warning {{unused}}
162 &g
<int>; // expected-error {{reference to overloaded function could not be resolved}}
166 template<typename T
> static int f(T
);
167 template<typename T
> static int g(T
);
168 template<typename T
> static int g(T
, int);
171 int k4
= f(&s
.f
); // expected-error {{non-constant pointer to member}}
172 int k5
= f(&s
.f
<int>);
173 int k6
= f(&s
.g
<int>); // expected-error {{non-constant pointer to member}}
176 (void)&s
.f
; // expected-error {{non-constant pointer to member}}
178 (void)&s
.g
<int>; // expected-error {{non-constant pointer to member}}
180 &s
.f
; // expected-error {{non-constant pointer to member}}
181 &s
.f
<int>; // expected-warning {{unused}}
182 &s
.g
<int>; // expected-error {{non-constant pointer to member}}
186 template<typename T
> int f(T
);
187 template<typename T
> int g(T
);
188 template<typename T
> int g(T
, int);
191 int k7
= f(&s
.f
); // expected-error {{non-constant pointer to member}}
192 int k8
= f(&s
.f
<int>);
193 int k9
= f(&s
.g
<int>); // expected-error {{non-constant pointer to member}}
196 (void)&s
.f
; // expected-error {{non-constant pointer to member}}
198 (void)&s
.g
<int>; // expected-error {{non-constant pointer to member}}
200 &s
.f
; // expected-error {{non-constant pointer to member}}
201 &s
.f
<int>; // expected-warning {{unused}}
202 &s
.g
<int>; // expected-error {{non-constant pointer to member}}
205 #if __cplusplus >= 201103L
206 // Special case kicks in only if a template argument list is specified.
207 template<typename T
=int> void with_default(); // expected-note +{{}}
208 int k10
= f(&with_default
); // expected-error {{no matching function}}
209 int k11
= f(&with_default
<>);
211 (void)&with_default
; // expected-error {{overloaded function}}
212 (void)&with_default
<>;
213 &with_default
; // expected-error {{overloaded function}}
214 &with_default
<>; // expected-warning {{unused}}
219 namespace dr116
{ // dr116: yes
220 template<int> struct A
{};
221 template<int N
> void f(A
<N
>) {} // expected-note {{previous}}
222 template<int M
> void f(A
<M
>) {} // expected-error {{redefinition}}
223 template<typename T
> void f(A
<sizeof(T
)>) {} // expected-note {{previous}}
224 template<typename U
> void f(A
<sizeof(U
)>) {} // expected-error {{redefinition}}
228 // dr118 is in its own file.
232 namespace dr121
{ // dr121: yes
234 template<typename T
> struct Y
{};
236 template<typename T
> struct Z
{
238 T::Y
<T
> y
; // expected-error +{{}}
243 namespace dr122
{ // dr122: yes
244 template<typename T
> void f();
245 void g() { f
<int>(); }
252 struct dr125_A
{ struct dr125_B
{}; }; // expected-note {{here}}
253 dr125_A::dr125_B
dr125_C();
254 namespace dr125_B
{ dr125_A
dr125_C(); }
257 friend dr125_A::dr125_B (::dr125_C
)(); // ok
258 friend dr125_A (::dr125_B::dr125_C
)(); // ok
259 friend dr125_A::dr125_B::dr125_C(); // expected-error {{did you mean the constructor name 'dr125_B'?}}
260 // expected-error@-1 {{missing exception specification}}
264 namespace dr126
{ // dr126: partial
265 // FIXME: We do not yet generate correct code for this change:
267 // catch (void*&) should catch void* but not int*
268 // catch (void*) and catch (void*const&) should catch both
270 // catch (Base *&) should catch Base* but not Derived*
271 // catch (Base *) should catch both
272 // In each case, we emit the same code for both catches.
274 // The ABI does not let us represent the language rule in the unwind tables.
275 // So, when catching by non-const (or volatile) reference to pointer, we
276 // should compare the exception type to the caught type and only accept an
278 #if __cplusplus <= 201402L
281 struct E
: private C
{ friend class A
; friend class B
; };
282 struct F
: protected C
{};
287 virtual void cp() throw(C
*);
288 virtual void dp() throw(C
*);
289 virtual void ep() throw(C
*); // expected-note {{overridden}}
290 virtual void fp() throw(C
*); // expected-note {{overridden}}
291 virtual void gp() throw(C
*);
292 virtual void hp() throw(C
*); // expected-note {{overridden}}
294 virtual void cr() throw(C
&);
295 virtual void dr() throw(C
&);
296 virtual void er() throw(C
&); // expected-note {{overridden}}
297 virtual void fr() throw(C
&); // expected-note {{overridden}}
298 virtual void gr() throw(C
&);
299 virtual void hr() throw(C
&); // expected-note {{overridden}}
301 virtual void pv() throw(void*);
303 #if __cplusplus >= 201103L
304 virtual void np() throw(C
*);
305 virtual void npm() throw(int C::*);
306 virtual void nr() throw(C
*&); // expected-note {{overridden}}
307 virtual void ncr() throw(C
*const&);
310 virtual void ref1() throw(C
*const&);
311 virtual void ref2() throw(C
*);
313 virtual void v() throw(int);
314 virtual void w() throw(const int);
315 virtual void x() throw(int*); // expected-note {{overridden}}
316 virtual void y() throw(const int*);
317 virtual void z() throw(int); // expected-note {{overridden}}
320 virtual void cp() throw(C
*);
321 virtual void dp() throw(D
*);
322 virtual void ep() throw(E
*); // expected-error {{more lax}}
323 virtual void fp() throw(F
*); // expected-error {{more lax}}
324 virtual void gp() throw(G
*);
325 virtual void hp() throw(H
*); // expected-error {{more lax}}
327 virtual void cr() throw(C
&);
328 virtual void dr() throw(D
&);
329 virtual void er() throw(E
&); // expected-error {{more lax}}
330 virtual void fr() throw(F
&); // expected-error {{more lax}}
331 virtual void gr() throw(G
&);
332 virtual void hr() throw(H
&); // expected-error {{more lax}}
334 virtual void pv() throw(C
*);
336 #if __cplusplus >= 201103L
337 using nullptr_t
= decltype(nullptr);
338 virtual void np() throw(nullptr_t
);
339 virtual void npm() throw(nullptr_t
&);
340 virtual void nr() throw(nullptr_t
); // expected-error {{more lax}}
341 virtual void ncr() throw(nullptr_t
);
344 virtual void ref1() throw(D
*const &);
345 virtual void ref2() throw(D
*);
347 virtual void v() throw(const int);
348 virtual void w() throw(int);
349 virtual void x() throw(const int*); // expected-error {{more lax}}
350 virtual void y() throw(int*); // ok
351 virtual void z() throw(long); // expected-error {{more lax}}
354 void f() throw(int); // expected-error {{ISO C++17 does not allow}} expected-note {{use 'noexcept}}
358 namespace dr127
{ // dr127: yes
359 __extension__
typedef __decltype(sizeof(0)) size_t;
360 template<typename T
> struct A
{
362 void *operator new(size_t, const char * = 0);
363 void operator delete(void *, const char *) { T::error
; } // expected-error 2{{no members}}
364 void operator delete(void *) { T::error
; }
366 A
<void> *p
= new A
<void>; // expected-note {{instantiat}}
367 A
<int> *q
= new ("") A
<int>; // expected-note {{instantiat}}
370 namespace dr128
{ // dr128: yes
371 enum E1
{ e1
} x
= e1
;
372 enum E2
{ e2
} y
= static_cast<E2
>(x
), z
= static_cast<E2
>(e1
);
378 namespace dr131
{ // dr131: sup P1949
379 const char *a_with_
\u0e8c = "\u0e8c";
380 const char *b_with_
\u0e8d = "\u0e8d";
381 const char *c_with_
\u0e8e = "\u0e8e";
384 namespace dr132
{ // dr132: no
386 extern struct {} x
; // ok
387 extern struct S
{} y
; // FIXME: This is invalid.
395 namespace dr135
{ // dr135: yes
397 A
f(A a
) { return a
; }
398 friend A
g(A a
) { return a
; }
399 static A
h(A a
) { return a
; }
403 namespace dr136
{ // dr136: 3.4
404 void f(int, int, int = 0); // expected-note {{previous declaration is here}}
405 void g(int, int, int); // expected-note {{previous declaration is here}}
407 friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
408 friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
409 friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
410 friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}}
411 friend void j(int, int, int = 0) {}
414 void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
416 j(A(), A()); // ok, has default argument
418 extern "C" void k(int, int, int, int); // expected-note 2{{previous declaration is here}}
421 friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
426 friend void dr136::k(int, int, int = 0, int); // expected-error {{missing default argument on parameter}} expected-error {{must be the only declaration}}
430 void f(int); // expected-note {{previous declaration is here}}
433 friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
437 namespace dr137
{ // dr137: yes
439 extern const void *cp
;
440 extern volatile void *vp
;
441 extern const volatile void *cvp
;
442 int *q
= static_cast<int*>(p
);
443 int *qc
= static_cast<int*>(cp
); // expected-error {{casts away qualifiers}}
444 int *qv
= static_cast<int*>(vp
); // expected-error {{casts away qualifiers}}
445 int *qcv
= static_cast<int*>(cvp
); // expected-error {{casts away qualifiers}}
446 const int *cq
= static_cast<const int*>(p
);
447 const int *cqc
= static_cast<const int*>(cp
);
448 const int *cqv
= static_cast<const int*>(vp
); // expected-error {{casts away qualifiers}}
449 const int *cqcv
= static_cast<const int*>(cvp
); // expected-error {{casts away qualifiers}}
450 const volatile int *cvq
= static_cast<const volatile int*>(p
);
451 const volatile int *cvqc
= static_cast<const volatile int*>(cp
);
452 const volatile int *cvqv
= static_cast<const volatile int*>(vp
);
453 const volatile int *cvqcv
= static_cast<const volatile int*>(cvp
);
456 namespace dr139
{ // dr139: yes
458 typedef int f
; // expected-note {{previous}}
460 friend void f(A
&); // expected-error {{different kind of symbol}}
470 void g(A a
) { int i
= f(a
); } // ok, f is typedef not friend function
476 namespace dr140
{ // dr140: yes
477 void f(int *const) {} // expected-note {{previous}}
478 void f(int[3]) {} // expected-error {{redefinition}}
480 void g(int n
) { n
= 2; }
483 namespace dr141
{ // dr141: yes
484 template<typename T
> void f();
485 template<typename T
> struct S
{ int n
; }; // expected-note {{'::dr141::S<int>::n' declared here}}
487 template<typename T
> void f();
488 template<typename T
> struct S
{};
490 struct B
: S
<int> {} b
;
493 (void)a
.S
<int>::n
; // expected-error {{no member named 'n' in 'dr141::A::S<int>'; did you mean '::dr141::S<int>::n'?}}
494 #if __cplusplus < 201103L
495 // expected-error@-2 {{ambiguous}}
496 // expected-note@-11 {{lookup from the current scope}}
497 // expected-note@-9 {{lookup in the object type}}
499 b
.f
<int>(); // expected-error {{no member}} expected-error +{{}}
502 template<typename T
> struct C
{
505 t
.f
<int>(); // expected-error {{use 'template'}}
508 (void)t
.S
<int>::n
; // ok
511 (void)t
.S
<int>(); // ok!
514 void h() { C
<B
>().h(); } // ok
516 template<typename T
> void S();
518 void i() { C
<X
>().i(); } // ok!!
521 namespace dr142
{ // dr142: yes
522 class B
{ // expected-note +{{here}}
524 int mi
; // expected-note +{{here}}
525 static int si
; // expected-note +{{here}}
527 class D
: private B
{ // expected-note +{{here}}
529 class DD
: public D
{
533 mi
= 3; // expected-error {{private member}}
534 si
= 3; // expected-error {{private member}}
535 B b_old
; // expected-error {{private member}}
539 B::si
= 3; // expected-error {{private member}}
541 B
*bp1_old
= this; // expected-error {{private member}} expected-error {{private base class}}
542 dr142::B
*bp1
= this; // expected-error {{private base class}}
543 B
*bp2_old
= (B
*)this; // expected-error 2{{private member}}
544 dr142::B
*bp2
= (dr142::B
*)this;
549 namespace dr143
{ // dr143: yes
550 namespace A
{ struct X
; }
551 namespace B
{ void f(A::X
); }
553 struct X
{ friend void B::f(X
); };
556 f(x
); // expected-error {{undeclared identifier 'f'}}
560 namespace dr145
{ // dr145: yes
562 #if __cplusplus <= 201402L
563 ++b
; // expected-warning {{deprecated}}
564 b
++; // expected-warning {{deprecated}}
566 ++b
; // expected-error {{increment}}
567 b
++; // expected-error {{increment}}
572 namespace dr147
{ // dr147: yes
574 template<typename
> struct A
{
575 template<typename T
> A(T
);
577 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
578 // name the injected-class-name. (A<int>::A does, though.)
579 template<> template<> A
<int>::A
<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}}
580 template<> template<> A
<float>::A(float) {}
584 struct B
: A
{ B(); };
585 A::A a1
; // expected-error {{is a constructor}}
589 template<typename
> struct A
{
590 template<typename T
> A(T
);
593 template<> A
<int>::A
<int>(A
<int>::a
); // expected-error {{is a constructor}}
597 namespace dr148
{ // dr148: yes
598 struct A
{ int A::*p
; };
599 int check1
[__is_pod(int(A::*)) ? 1 : -1];
600 int check2
[__is_pod(A
) ? 1 : -1];
605 namespace dr151
{ // dr151: yes
608 #if __cplusplus < 201103L
609 #define fold(x) (__builtin_constant_p(0) ? (x) : (x))
613 int check
[fold(p() == 0) ? 1 : -1];
617 namespace dr152
{ // dr152: yes
619 A(); // expected-note 0-2{{not viable}}
620 explicit A(const A
&); // expected-note 1-2{{not a candidate}}
623 #if __cplusplus <= 201402L
624 // expected-error@-2 {{no matching constructor}}
629 A a3
= f(); // expected-error {{no matching constructor}}
635 namespace dr154
{ // dr154: yes
636 union { int a
; }; // expected-error {{must be declared 'static'}}
640 static union { int c
; };
643 namespace dr155
{ // dr155: dup 632
644 struct S
{ int n
; } s
= { { 1 } }; // expected-warning {{braces around scalar initializer}}
647 // dr158 is in its own file.
649 namespace dr159
{ // dr159: 3.5
650 namespace X
{ void f(); }
652 void dr159::f() {} // expected-warning {{extra qualification}}
653 void dr159::X::f() {}
658 namespace dr161
{ // dr161: yes
661 struct B
{ int n
; } b
; // expected-note 2{{here}}
663 void f(); // expected-note {{here}}
671 C::B b2
; // ok, accessible as a member of A
672 (void)&C::b
; // expected-error {{protected}}
674 (void)c
.b
; // expected-error {{protected}}
678 c
.f(); // expected-error {{protected}}
689 namespace dr162
{ // dr162: no
695 int &a
= (&A::f
)(0); // FIXME: expected-error {{could not be resolved}}
696 char &b
= (&A::f
)('0'); // expected-error {{could not be resolved}}
700 int &c
= (&A::f
)(0); // FIXME: expected-error {{could not be resolved}}
701 char &d
= (&A::f
)('0'); // expected-error {{could not be resolved}}
706 namespace dr164
{ // dr164: yes
708 template <class T
> int g(T t
) { return f(t
); }
716 namespace dr165
{ // dr165: no
718 struct A
{ friend struct B
; };
719 void f() { void g(); }
721 // FIXME: dr1477 says this is ok, dr165 says it's ill-formed
723 // FIXME: dr165 says this is ill-formed, but the argument in dr1477 says it's ok
727 namespace dr166
{ // dr166: yes
728 namespace A
{ class X
; }
730 template<typename T
> int f(T t
) { return t
.n
; }
732 template<typename T
> int h(T t
) { return t
.n
; } // expected-error {{private}}
738 friend int dr166::g(X
);
741 int n
; // expected-note 2{{here}}
744 int h(X x
) { return x
.n
; }
745 int i(X x
) { return x
.n
; }
748 template int f(A::X
);
749 int g(A::X x
) { return x
.n
; }
750 template int h(A::X
); // expected-note {{instantiation}}
751 int i(A::X x
) { return x
.n
; } // expected-error {{private}}
756 namespace dr168
{ // dr168: no
757 extern "C" typedef int (*p
)();
758 extern "C++" typedef int (*q
)();
762 p a
= &S::f
; // FIXME: this should fail.
766 namespace dr169
{ // dr169: yes
767 template<typename
> struct A
{ int n
; };
769 template<typename
> struct C
;
770 template<typename
> void f();
771 template<typename
> static int n
; // expected-error 0-1{{extension}}
773 struct D
: A
<int>, B
{
775 using B::C
<int>; // expected-error {{using declaration cannot refer to a template specialization}}
776 using B::f
<int>; // expected-error {{using declaration cannot refer to a template specialization}}
777 using B::n
<int>; // expected-error {{using declaration cannot refer to a template specialization}}
781 namespace { // dr171: yes
784 int dr171b
; // expected-note {{here}}
786 extern "C" void dr171a();
787 extern "C" void dr171b(); // expected-error {{conflicts}}
790 namespace dr172
{ // dr172: yes
792 int check1
[-1 < zero
? 1 : -1];
794 enum { x
= -1, y
= (unsigned int)-1 };
795 int check2
[sizeof(x
) > sizeof(int) ? 1 : -1];
797 enum { a
= (unsigned int)-1 / 2 };
798 int check3a
[sizeof(a
) == sizeof(int) ? 1 : -1];
799 int check3b
[-a
< 0 ? 1 : -1];
801 enum { b
= (unsigned int)-1 / 2 + 1 };
802 int check4a
[sizeof(b
) == sizeof(unsigned int) ? 1 : -1];
803 int check4b
[-b
> 0 ? 1 : -1];
805 enum { c
= (unsigned long)-1 / 2 };
806 int check5a
[sizeof(c
) == sizeof(long) ? 1 : -1];
807 int check5b
[-c
< 0 ? 1 : -1];
809 enum { d
= (unsigned long)-1 / 2 + 1 };
810 int check6a
[sizeof(d
) == sizeof(unsigned long) ? 1 : -1];
811 int check6b
[-d
> 0 ? 1 : -1];
813 enum { e
= (unsigned long long)-1 / 2 }; // expected-error 0-1{{extension}}
814 int check7a
[sizeof(e
) == sizeof(long) ? 1 : -1]; // expected-error 0-1{{extension}}
815 int check7b
[-e
< 0 ? 1 : -1];
817 enum { f
= (unsigned long long)-1 / 2 + 1 }; // expected-error 0-1{{extension}}
818 int check8a
[sizeof(f
) == sizeof(unsigned long) ? 1 : -1]; // expected-error 0-1{{extension}}
819 int check8b
[-f
> 0 ? 1 : -1];
822 namespace dr173
{ // dr173: yes
823 int check
[('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
824 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
825 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9') ? 1 : -1];
830 namespace dr175
{ // dr175: yes
831 struct A
{}; // expected-note {{here}}
832 struct B
: private A
{}; // expected-note {{constrained by private inheritance}}
834 A a
; // expected-error {{private}}
839 namespace dr176
{ // dr176: yes
840 template<typename T
> class Y
;
841 template<> class Y
<int> {
843 typedef Y A
; // expected-note {{here}}
844 typedef Y
<char> A
; // expected-error {{different types ('Y<char>' vs 'Y<int>')}}
848 template<typename T
> struct Base
{}; // expected-note 2{{found}}
849 template<typename T
> struct Derived
: public Base
<T
> {
851 typedef typename
Derived::template Base
<T
> A
;
852 typedef typename
Derived::Base A
;
855 template struct Derived
<int>;
857 template<typename T
> struct Derived2
: Base
<int>, Base
<char> {
858 typename
Derived2::Base b
; // expected-error {{found in multiple base classes}}
859 typename
Derived2::Base
<double> d
;
862 template<typename T
> class X
{ // expected-note {{here}}
866 dr176::X
*p4
; // expected-error {{requires template arguments}}
870 namespace dr177
{ // dr177: yes
873 A(A
&); // expected-note 0-1{{not viable: expects an lvalue}}
874 A(const B
&); // expected-note 0-1{{not viable: no known conversion from 'A' to}}
878 #if __cplusplus <= 201402L
879 // expected-error@-2 {{no viable constructor copying variable}}
882 struct C
{ C(C
&); }; // expected-note {{not viable: expects an lvalue for 1st argument}}
884 struct E
{ operator D(); };
886 C c
= e
; // expected-error {{no viable constructor copying variable of type 'D'}}
889 namespace dr178
{ // dr178: yes
890 int check
[int() == 0 ? 1 : -1];
891 #if __cplusplus >= 201103L
892 static_assert(int{} == 0, "");
893 struct S
{ int a
, b
; };
894 static_assert(S
{1}.b
== 0, "");
895 struct T
{ constexpr T() : n() {} int n
; };
896 static_assert(T().n
== 0, "");
897 struct U
: S
{ constexpr U() : S() {} };
898 static_assert(U().b
== 0, "");
902 namespace dr179
{ // dr179: yes
904 int n
= &f
- &f
; // expected-error {{arithmetic on pointers to the function type 'void ()'}}
907 namespace dr180
{ // dr180: yes
908 template<typename T
> struct X
: T
, T::some_base
{
909 X() : T::some_type_that_might_be_T(), T::some_base() {}
910 friend class T::some_class
;
917 namespace dr181
{ // dr181: yes
919 template <template X
<class T
> > struct A
{ }; // expected-error +{{}}
920 template <template X
<class T
> > void f(A
<X
>) { } // expected-error +{{}}
924 template <template <class T
> class X
> struct A
{ };
925 template <template <class T
> class X
> void f(A
<X
>) { }
929 namespace dr182
{ // dr182: yes
930 template <class T
> struct C
{
935 template <class T
> void C
<T
>::f() {}
936 template <class T
> void C
<T
>::g() {}
943 template void C
<A::B
>::f();
944 template <> void C
<A::B
>::g();
952 namespace dr183
{ // dr183: sup 382
953 template<typename T
> struct A
{};
954 template<typename T
> struct B
{
957 template<> struct A
<int> {
958 #if __cplusplus <= 199711
959 typename B
<int>::X x
; // expected-error {{'typename' occurs outside of a template}}
961 typename B
<int>::X x
;
966 namespace dr184
{ // dr184: yes
967 template<typename T
= float> struct B
{};
969 template<template<typename TT
= float> class T
> struct A
{
974 template<template<typename TT
> class T
> void A
<T
>::f() { // expected-note {{here}}
975 T
<> t
; // expected-error {{too few template arguments}}
978 template<template<typename TT
= char> class T
> void A
<T
>::g() {
984 void h() { A
<B
>().g(); }
987 // dr185 FIXME: add codegen test
989 namespace dr187
{ // dr187: sup 481
991 template<int X
= Z
, int Z
= X
> struct A
;
996 namespace dr188
{ // dr188: yes
998 int check
[sizeof(0, c
) == 10 ? 1 : -1];
1001 // dr190 FIXME: add codegen test for tbaa
1004 namespace dr191
{ // dr191: yes
1005 namespace example1
{
1020 namespace example2
{
1033 // dr193 FIXME: add codegen test
1035 namespace dr194
{ // dr194: yes
1038 void A(); // expected-error {{constructor cannot have a return type}}
1041 void B(); // expected-error {{constructor cannot have a return type}}
1045 inline explicit C(int) {}
1049 namespace dr195
{ // dr195: yes
1051 int *p
= (int*)&f
; // expected-error 0-1{{extension}}
1052 void (*q
)() = (void(*)())&p
; // expected-error 0-1{{extension}}
1055 namespace dr197
{ // dr197: yes
1058 template <class T
> void g(T t
) {
1060 char &b
= f(T(1)); // expected-error {{unrelated type 'int'}}
1061 char &c
= f(t
); // expected-error {{unrelated type 'int'}}
1072 g(e
); // expected-note {{in instantiation of}}
1076 namespace dr198
{ // dr198: yes
1081 #if __cplusplus < 201103L
1082 // expected-error@-2 {{invalid use of non-static data member}}
1084 int f() { return n
; }
1085 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1092 #if __cplusplus < 201103L
1093 // expected-error@-2 {{invalid use of non-static data member}}
1095 int f() { return n
; }
1096 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1100 #if __cplusplus < 201103L
1101 // expected-error@-2 {{invalid use of non-static data member}}
1103 int f() { return n
; }
1107 // dr199 FIXME: add codegen test