1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
8 #if __cplusplus == 199711L
9 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
10 // cxx98-error@-1 {{variadic macros are a C99 feature}}
13 #if __cplusplus == 199711L
14 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
16 #define __enable_constant_folding
19 namespace cwg100
{ // cwg100: yes
20 template<const char (*)[4]> struct A
{}; // #cwg100-A
21 template<const char (&)[4]> struct B
{}; // #cwg100-B
22 template<const char *> struct C
{}; // #cwg100-C
23 template<const char &> struct D
{}; // #cwg100-D
24 A
<&"foo"> a
; // #cwg100-a
25 // cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}}
26 // cxx98-14-note@#cwg100-A {{template parameter is declared here}}
27 // since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}}
28 B
<"bar"> b
; // #cwg100-b
29 // cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}}
30 // cxx98-14-note@#cwg100-B {{template parameter is declared here}}
31 // since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}}
32 C
<"baz"> c
; // #cwg100-c
33 // cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}}
34 // cxx98-14-note@#cwg100-C {{template parameter is declared here}}
35 // since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}}
36 D
<*"quux"> d
; // #cwg100-d
37 // cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}}
38 // cxx98-14-note@#cwg100-D {{template parameter is declared here}}
39 // since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}}
42 namespace cwg101
{ // cwg101: 3.5
43 extern "C" void cwg101_f();
44 typedef unsigned size_t;
46 extern "C" void cwg101_f();
47 typedef unsigned size_t;
51 extern "C" void cwg101_f();
52 typedef unsigned size_t;
55 namespace cwg102
{ // cwg102: yes
57 template<typename T
> T
f(T a
, T b
) { return a
+ b
; }
58 // expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
59 // expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f<cwg102::B::S>' requested here}}
60 // expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}}
65 B::S
operator+(B::S
, B::S
); // #cwg102-operator-plus
66 template B::S
A::f(B::S
, B::S
); // #cwg102-instantiation
73 namespace cwg106
{ // cwg106: sup 540
77 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}
79 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}
81 typedef const int &r2
;
84 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}
86 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}
89 namespace cwg107
{ // cwg107: yes
91 extern "C" S
operator+(S
, S
) { return S(); }
94 namespace cwg108
{ // cwg108: 2.9
95 template<typename T
> struct A
{
96 struct B
{ typedef int X
; };
98 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}}
99 struct C
: B
{ X x
; };
100 // expected-error@-1 {{unknown type name 'X'}}
102 template<> struct A
<int>::B
{ int X
; };
105 namespace cwg109
{ // cwg109: yes
106 struct A
{ template<typename T
> void f(T
); };
107 template<typename T
> struct B
: T
{
109 // expected-error@-1 {{'template' keyword not permitted here}}
110 using T::template f
<int>;
111 // expected-error@-1 {{'template' keyword not permitted here}}
112 // expected-error@-2 {{using declaration cannot refer to a template specialization}}
113 // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.
115 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
116 // expected-error@-2 {{using declaration cannot refer to a template specialization}}
117 void g() { this->f
<int>(123); }
118 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
122 namespace cwg110
{ // cwg110: 2.8
123 template <typename T
>
128 template <typename T
>
132 void (*h
)(int) = static_cast<void(*)(int)>(f
);
133 void (*i
)(int, int) = static_cast<void(*)(int, int)>(f
);
134 } // namespace cwg110
136 namespace cwg111
{ // cwg111: dup 535
137 struct A
{ A(); A(volatile A
&, int = 0); A(A
&, const char * = "foo"); };
138 struct B
: A
{ B(); }; // #cwg111-B
141 // expected-error@-1 {{no matching constructor for initialization of 'B'}}
142 // expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}}
143 // expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
146 namespace cwg112
{ // cwg112: yes
150 const T a1
[1] = {}; // #cwg112-a1
151 volatile T a2
[1] = {};
152 const Arr a3
= {}; // #cwg112-a3
153 volatile Arr a4
= {};
154 template<const volatile T
*> struct X
{};
155 // FIXME: Test this somehow in C++11 and on.
157 // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}}
158 // cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}}
161 // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}}
162 // cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}}
166 namespace cwg113
{ // cwg113: yes
170 // expected-error@-1 {{use of undeclared identifier 'no_such_function'}}
177 namespace cwg114
{ // cwg114: yes
179 virtual void f(int) = 0; // #cwg114-A-f
182 template<typename T
> void f(T
);
185 // expected-error@-1 {{variable type 'struct B' is an abstract class}}
186 // expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}}
189 namespace cwg115
{ // cwg115: 3.0
190 template<typename T
> int f(T
); // #cwg115-f
191 template<typename T
> int g(T
); // #cwg115-g
192 template<typename T
> int g(T
, int); // #cwg115-g-int
195 // expected-error@-1 {{no matching function for call to 'f'}}
196 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
199 // expected-error@-1 {{no matching function for call to 'f'}}
200 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
204 // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}}
205 // expected-note@#cwg115-f {{candidate function template}}
208 // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}}
209 // expected-note@#cwg115-g-int {{candidate function template}}
210 // expected-note@#cwg115-g {{candidate function template}}
213 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
214 // expected-note@#cwg115-f {{possible target for call}}
216 // expected-warning@-1 {{expression result unused}}
218 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
219 // expected-note@#cwg115-g-int {{possible target for call}}
220 // expected-note@#cwg115-g {{possible target for call}}
224 template<typename T
> static int f(T
);
225 template<typename T
> static int g(T
);
226 template<typename T
> static int g(T
, int);
230 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
231 int k5
= f(&s
.f
<int>);
232 int k6
= f(&s
.g
<int>);
233 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
237 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
240 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
243 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
245 // expected-warning@-1 {{expression result unused}}
247 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
251 template<typename T
> int f(T
);
252 template<typename T
> int g(T
);
253 template<typename T
> int g(T
, int);
257 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
258 int k8
= f(&s
.f
<int>);
259 int k9
= f(&s
.g
<int>);
260 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
264 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
267 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
270 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
272 // expected-warning@-1 {{expression result unused}}
274 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
277 #if __cplusplus >= 201103L
278 // Special case kicks in only if a template argument list is specified.
279 template<typename T
=int> void with_default(); // #cwg115-with-default
280 int k10
= f(&with_default
);
281 // expected-error@-1 {{no matching function for call to 'f'}}
282 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
283 int k11
= f(&with_default
<>);
286 // expected-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}}
287 // expected-note@#cwg115-with-default {{candidate function template}}
288 (void)&with_default
<>;
290 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
291 // expected-note@#cwg115-with-default {{possible target for call}}
293 // expected-warning@-1 {{expression result unused}}
298 namespace cwg116
{ // cwg116: yes
299 template<int> struct A
{};
300 template<int N
> void f(A
<N
>) {} // #cwg116-f-N
301 template<int M
> void f(A
<M
>) {}
302 // expected-error@-1 {{redefinition of 'f'}}
303 // expected-note@#cwg116-f-N {{previous definition is here}}
304 template<typename T
> void f(A
<sizeof(T
)>) {} // #cwg116-f-T
305 template<typename U
> void f(A
<sizeof(U
)>) {}
306 // expected-error@-1 {{redefinition of 'f'}}
307 // expected-note@#cwg116-f-T {{previous definition is here}}
311 // cwg118 is in cwg118.cpp
315 namespace cwg121
{ // cwg121: yes
317 template<typename T
> struct Y
{};
319 template<typename T
> struct Z
{
322 // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}}
323 // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name T::Y; implicit 'typename' is a C++20 extension}}
328 namespace cwg122
{ // cwg122: yes
329 template<typename T
> void f();
330 void g() { f
<int>(); }
334 // cwg124 is in cwg124.cpp
337 struct cwg125_A
{ struct cwg125_B
{}; }; // #cwg125_B
338 cwg125_A::cwg125_B
cwg125_C();
339 namespace cwg125_B
{ cwg125_A
cwg125_C(); }
342 friend cwg125_A::cwg125_B (::cwg125_C
)(); // ok
343 friend cwg125_A (::cwg125_B::cwg125_C
)(); // ok
344 friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C
345 // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}}
346 // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}}
347 // cxx98-note@#cwg125_B {{previous declaration is here}}
348 // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}}
349 // since-cxx11-note@#cwg125_B {{previous declaration is here}}
353 namespace cwg126
{ // cwg126: partial
354 // FIXME: We do not yet generate correct code for this change:
356 // catch (void*&) should catch void* but not int*
357 // catch (void*) and catch (void*const&) should catch both
359 // catch (Base *&) should catch Base* but not Derived*
360 // catch (Base *) should catch both
361 // In each case, we emit the same code for both catches.
363 // The ABI does not let us represent the language rule in the unwind tables.
364 // So, when catching by non-const (or volatile) reference to pointer, we
365 // should compare the exception type to the caught type and only accept an
369 struct E
: private C
{ friend class A
; friend class B
; };
370 struct F
: protected C
{};
374 #if __cplusplus <= 201402L
376 virtual void cp() throw(C
*);
377 virtual void dp() throw(C
*);
378 virtual void ep() throw(C
*); // #cwg126-ep
379 virtual void fp() throw(C
*); // #cwg126-fp
380 virtual void gp() throw(C
*);
381 virtual void hp() throw(C
*); // #cwg126-hp
383 virtual void cr() throw(C
&);
384 virtual void dr() throw(C
&);
385 virtual void er() throw(C
&); // #cwg126-er
386 virtual void fr() throw(C
&); // #cwg126-fr
387 virtual void gr() throw(C
&);
388 virtual void hr() throw(C
&); // #cwg126-hr
390 virtual void pv() throw(void*);
392 virtual void np() throw(C
*);
393 virtual void npm() throw(int C::*);
394 virtual void nr() throw(C
*&); // #cwg126-nr
395 virtual void ncr() throw(C
*const&);
397 virtual void ref1() throw(C
*const&);
398 virtual void ref2() throw(C
*);
400 virtual void v() throw(int);
401 virtual void w() throw(const int);
402 virtual void x() throw(int*); // #cwg126-x
403 virtual void y() throw(const int*);
404 virtual void z() throw(int); // #cwg126-z
407 virtual void cp() throw(C
*);
408 virtual void dp() throw(D
*);
409 virtual void ep() throw(E
*);
410 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
411 // cxx98-14-note@#cwg126-ep {{overridden virtual function is here}}
412 virtual void fp() throw(F
*);
413 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
414 // cxx98-14-note@#cwg126-fp {{overridden virtual function is here}}
415 virtual void gp() throw(G
*);
416 virtual void hp() throw(H
*);
417 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
418 // cxx98-14-note@#cwg126-hp {{overridden virtual function is here}}
420 virtual void cr() throw(C
&);
421 virtual void dr() throw(D
&);
422 virtual void er() throw(E
&);
423 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
424 // cxx98-14-note@#cwg126-er {{overridden virtual function is here}}
425 virtual void fr() throw(F
&);
426 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
427 // cxx98-14-note@#cwg126-fr {{overridden virtual function is here}}
428 virtual void gr() throw(G
&);
429 virtual void hr() throw(H
&);
430 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
431 // cxx98-14-note@#cwg126-hr {{overridden virtual function is here}}
433 virtual void pv() throw(C
*);
435 #if __cplusplus >= 201103L
436 using nullptr_t
= decltype(nullptr);
437 virtual void np() throw(nullptr_t
);
438 virtual void npm() throw(nullptr_t
&);
439 virtual void nr() throw(nullptr_t
);
440 // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}}
441 // cxx11-14-note@#cwg126-nr {{overridden virtual function is here}}
442 virtual void ncr() throw(nullptr_t
);
443 #endif // __cplusplus >= 201103L
445 virtual void ref1() throw(D
*const &);
446 virtual void ref2() throw(D
*);
448 virtual void v() throw(const int);
449 virtual void w() throw(int);
450 virtual void x() throw(const int*);
451 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
452 // cxx98-14-note@#cwg126-x {{overridden virtual function is here}}
453 virtual void y() throw(int*); // ok
454 virtual void z() throw(long);
455 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
456 // cxx98-14-note@#cwg126-z {{overridden virtual function is here}}
458 #endif // __cplusplus <= 201402L
460 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
461 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
464 namespace cwg127
{ // cwg127: 2.9
465 __extension__
typedef __decltype(sizeof(0)) size_t;
466 template<typename T
> struct A
{
468 void *operator new(size_t, const char * = 0);
469 void operator delete(void *, const char *) { T::error
; } // #cwg127-delete-const-char
470 // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}}
471 // expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}}
472 // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}}
473 // expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}}
474 void operator delete(void *) { T::error
; }
476 A
<void> *p
= new A
<void>; // #cwg127-p
477 A
<int> *q
= new ("") A
<int>; // #cwg127-q
480 namespace cwg128
{ // cwg128: yes
481 enum E1
{ e1
} x
= e1
;
482 enum E2
{ e2
} y
= static_cast<E2
>(x
), z
= static_cast<E2
>(e1
);
488 namespace cwg131
{ // cwg131: sup P1949
489 const char *a_with_
\u0e8c = "\u0e8c";
490 const char *b_with_
\u0e8d = "\u0e8d";
491 const char *c_with_
\u0e8e = "\u0e8e";
494 namespace cwg132
{ // cwg132: no
496 extern struct {} x
; // ok
497 extern struct S
{} y
; // FIXME: This is invalid.
505 namespace cwg135
{ // cwg135: yes
507 A
f(A a
) { return a
; }
508 friend A
g(A a
) { return a
; }
509 static A
h(A a
) { return a
; }
513 namespace cwg136
{ // cwg136: 3.4
514 void f(int, int, int = 0); // #cwg136-f
515 void g(int, int, int); // #cwg136-g
517 friend void f(int, int = 0, int);
518 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
519 // expected-note@#cwg136-f {{previous declaration is here}}
520 friend void g(int, int, int = 0);
521 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
522 // expected-note@#cwg136-g {{previous declaration is here}}
523 friend void h(int, int, int = 0);
524 // expected-error@-1 {{friend declaration specifying a default argument must be a definition}}
525 friend void i(int, int, int = 0) {} // #cwg136-A-i
526 friend void j(int, int, int = 0) {}
529 void i(int, int, int);
530 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
531 // expected-note@#cwg136-A-i {{previous declaration is here}}
533 j(A(), A()); // ok, has default argument
535 extern "C" void k(int, int, int, int); // #cwg136-k
538 friend void cwg136::k(int, int, int, int = 0);
539 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
540 // expected-note@#cwg136-k {{previous declaration is here}}
545 friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k
546 // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}}
547 // expected-note@#cwg136-k {{previous declaration is here}}
548 // expected-error@#cwg136-friend-k {{missing default argument on parameter}}
552 void f(int); // #cwg136-B-f
555 friend void B::f(int = 0);
556 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
557 // expected-note@#cwg136-B-f {{previous declaration is here}}
561 namespace cwg137
{ // cwg137: yes
563 extern const void *cp
;
564 extern volatile void *vp
;
565 extern const volatile void *cvp
;
566 int *q
= static_cast<int*>(p
);
567 int *qc
= static_cast<int*>(cp
);
568 // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}}
569 int *qv
= static_cast<int*>(vp
);
570 // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}}
571 int *qcv
= static_cast<int*>(cvp
);
572 // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}}
573 const int *cq
= static_cast<const int*>(p
);
574 const int *cqc
= static_cast<const int*>(cp
);
575 const int *cqv
= static_cast<const int*>(vp
);
576 // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}}
577 const int *cqcv
= static_cast<const int*>(cvp
);
578 // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}}
579 const volatile int *cvq
= static_cast<const volatile int*>(p
);
580 const volatile int *cvqc
= static_cast<const volatile int*>(cp
);
581 const volatile int *cvqv
= static_cast<const volatile int*>(vp
);
582 const volatile int *cvqcv
= static_cast<const volatile int*>(cvp
);
585 namespace cwg138
{ // cwg138: partial
587 void foo(); // #cwg138-ex1-foo
589 using example1::foo
; // #cwg138-ex1-using
591 static const int i
= 10;
592 // This friend declaration is using neither qualified-id nor template-id,
593 // so name 'foo' is not looked up, which means the using-declaration has no effect.
594 // Target scope of this declaration is A, so this is grating friendship to
595 // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to.
596 // A::foo corresponds to example1::foo named by the using declaration,
597 // and since A::foo is a different entity, they potentially conflict.
598 // FIXME: This is ill-formed, but not for the reason diagnostic says.
600 // expected-error@-1 {{cannot befriend target of using declaration}}
601 // expected-note@#cwg138-ex1-foo {{target of using declaration}}
602 // expected-note@#cwg138-ex1-using {{using declaration}}
605 } // namespace example1
614 static const int i
= 10;
616 // Both friend declaration are not using qualified-ids or template-ids,
617 // so 'f' and 'g' are not looked up, which means that presence of A::f
618 // and base B have no effect.
619 // Both target scope of namespace 'example2', and grant friendship to
620 // example2::f and example2::g respectively.
630 } // namespace example2
635 static const int i
= 10; // #cwg138-ex3-Base-i
639 // Elaborated type specifier is not the sole constituent of declaration,
640 // so 'Data' undergoes unqualified type-only lookup, which finds Base::Data.
652 // expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}}
653 // expected-note@#cwg138-ex3-Base-i {{declared private here}}
656 } // namespace example3
657 } // namespace cwg138
659 namespace cwg139
{ // cwg139: yes
661 typedef int f
; // #cwg139-typedef-f
664 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}
665 // expected-note@#cwg139-typedef-f {{previous definition is here}}
675 void g(A a
) { int i
= f(a
); } // ok, f is typedef not friend function
681 namespace cwg140
{ // cwg140: yes
682 void f(int *const) {} // #cwg140-f-first
684 // expected-error@-1 {{redefinition of 'f'}}
685 // expected-note@#cwg140-f-first {{previous definition is here}}
687 void g(int n
) { n
= 2; }
690 namespace cwg141
{ // cwg141: 3.1
691 template<typename T
> void f();
692 template<typename T
> struct S
{ int n
; }; // #cwg141-S
694 template<typename T
> void f();
695 template<typename T
> struct S
{}; // #cwg141-A-S
697 struct B
: S
<int> {} b
;
700 (void)a
.S
<int>::n
; // #cwg141-a
701 // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}}
702 // cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}}
703 // cxx98-note@#cwg141-S {{lookup from the current scope refers here}}
704 // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'; did you mean '::cwg141::S<int>::n'?}}
705 // expected-note@#cwg141-S {{'::cwg141::S<int>::n' declared here}}
706 // FIXME: we issue a useful diagnostic first, then some bogus ones.
708 // expected-error@-1 {{no member named 'f' in 'cwg141::B'}}
709 // expected-error@-2 +{{}}
712 template<typename T
> struct C
{
716 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
719 (void)t
.S
<int>::n
; // ok
722 (void)t
.S
<int>(); // ok!
725 void h() { C
<B
>().h(); } // ok
727 template<typename T
> void S();
729 void i() { C
<X
>().i(); } // ok!!
732 namespace cwg142
{ // cwg142: 2.8
733 class B
{ // #cwg142-B
735 int mi
; // #cwg142-B-mi
736 static int si
; // #cwg142-B-si
738 class D
: private B
{ // #cwg142-D
740 class DD
: public D
{
745 // expected-error@-1 {{'mi' is a private member of 'cwg142::B'}}
746 // expected-note@#cwg142-D {{constrained by private inheritance here}}
747 // expected-note@#cwg142-B-mi {{member is declared here}}
749 // expected-error@-1 {{'si' is a private member of 'cwg142::B'}}
750 // expected-note@#cwg142-D {{constrained by private inheritance here}}
751 // expected-note@#cwg142-B-si {{member is declared here}}
753 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
754 // expected-note@#cwg142-D {{constrained by private inheritance here}}
755 // expected-note@#cwg142-B {{member is declared here}}
760 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
761 // expected-note@#cwg142-D {{constrained by private inheritance here}}
762 // expected-note@#cwg142-B {{member is declared here}}
764 B
*bp1_old
= this; // #cwg142-bp1_old
765 // expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}}
766 // expected-note@#cwg142-D {{constrained by private inheritance here}}
767 // expected-note@#cwg142-B {{member is declared here}}
768 // expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}}
769 // expected-note@#cwg142-D {{declared private here}}
770 cwg142::B
*bp1
= this;
771 // expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}}
772 // expected-note@#cwg142-D {{declared private here}}
773 B
*bp2_old
= (B
*)this; // #cwg142-bp2_old
774 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
775 // expected-note@#cwg142-D {{constrained by private inheritance here}}
776 // expected-note@#cwg142-B {{member is declared here}}
777 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
778 // expected-note@#cwg142-D {{constrained by private inheritance here}}
779 // expected-note@#cwg142-B {{member is declared here}}
780 cwg142::B
*bp2
= (cwg142::B
*)this;
785 namespace cwg143
{ // cwg143: yes
786 namespace A
{ struct X
; }
787 namespace B
{ void f(A::X
); }
789 struct X
{ friend void B::f(X
); };
793 // expected-error@-1 {{use of undeclared identifier 'f'}}
797 namespace cwg145
{ // cwg145: yes
800 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
801 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
803 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
804 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
808 namespace cwg147
{ // cwg147: yes
810 template<typename
> struct A
{
811 template<typename T
> A(T
);
813 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
814 // name the injected-class-name. (A<int>::A does, though.)
815 template<> template<> A
<int>::A
<int>(int) {}
816 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}}
817 template<> template<> A
<float>::A(float) {}
821 struct B
: A
{ B(); };
823 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}}
827 template<typename
> struct A
{
828 template<typename T
> A(T
);
831 template<> A
<int>::A
<int>(A
<int>::a
);
832 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}}
836 namespace cwg148
{ // cwg148: yes
837 struct A
{ int A::*p
; };
838 static_assert(__is_pod(int(A::*)), "");
839 static_assert(__is_pod(A
), "");
844 namespace cwg150
{ // cwg150: 19
846 template <class T
, class U
= int>
849 template <class X
, template <class Y
> class PARM
>
859 template <template <class T
, class U
= int> class PARM
>
866 struct Dense
{ static const unsigned int dim
= 1; };
868 template <template <typename
> class View
,
870 void operator+(float, View
<Block
> const&);
872 template <typename Block
,
873 unsigned int Dim
= Block::dim
>
874 class Lvalue_proxy
{ operator float() const; };
876 void test_1d (void) {
877 Lvalue_proxy
<Dense
> p
;
884 namespace cwg151
{ // cwg151: 3.1
887 static_assert(__enable_constant_folding(p() == 0), "");
890 namespace cwg152
{ // cwg152: yes
892 A(); // #cwg152-A-ctor
893 explicit A(const A
&); // #cwg152-A-explicit-ctor
896 // cxx98-14-error@-1 {{no matching constructor for initialization of 'A'}}
897 // cxx98-14-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
898 // cxx98-14-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
903 // expected-error@-1 {{no matching constructor for initialization of 'A'}}
904 // expected-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
905 // expected-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
911 namespace cwg154
{ // cwg154: yes
913 // expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}}
917 static union { int c
; };
920 namespace cwg155
{ // cwg155: dup 632
921 struct S
{ int n
; } s
= { { 1 } };
922 // expected-warning@-1 {{braces around scalar initializer}}
925 // cwg158 is in cwg158.cpp
927 namespace cwg159
{ // cwg159: 3.5
928 namespace X
{ void f(); }
931 // expected-warning@-1 {{extra qualification on member 'f'}}
932 void cwg159::X::f() {}
937 namespace cwg161
{ // cwg161: 3.1
940 struct B
{ int n
; } b
; // #cwg161-B
942 void f(); // #cwg161-f
950 C::B b2
; // ok, accessible as a member of A
952 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
953 // expected-note@#cwg161-B {{declared protected here}}
956 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
957 // expected-note@#cwg161-B {{declared protected here}}
962 // expected-error@-1 {{protected}}
963 // expected-note@#cwg161-f {{declared protected here}}
974 namespace cwg162
{ // cwg162: 19
981 char &b
= (&A::f
)('0');
982 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
987 char &d
= (&A::f
)('0');
988 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
993 namespace cwg164
{ // cwg164: yes
995 template <class T
> int g(T t
) { return f(t
); }
1003 namespace cwg165
{ // cwg165: no
1005 struct A
{ friend struct B
; };
1006 void f() { void g(); }
1008 // FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed
1010 // FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok
1014 namespace cwg166
{ // cwg166: 2.9
1015 namespace A
{ class X
; }
1017 template<typename T
> int f(T t
) { return t
.n
; }
1019 template<typename T
> int h(T t
) { return t
.n
; }
1020 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
1021 // expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}}
1022 // expected-note@#cwg166-X-n {{implicitly declared private here}}
1028 friend int cwg166::g(X
);
1031 int n
; // #cwg166-X-n
1034 int h(X x
) { return x
.n
; }
1035 int i(X x
) { return x
.n
; }
1038 template int f(A::X
);
1039 int g(A::X x
) { return x
.n
; }
1040 template int h(A::X
); // #cwg166-h-instantiation
1041 int i(A::X x
) { return x
.n
; }
1042 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
1043 // expected-note@#cwg166-X-n {{implicitly declared private here}}
1048 namespace cwg168
{ // cwg168: no
1049 extern "C" typedef int (*p
)();
1050 extern "C++" typedef int (*q
)();
1054 p a
= &S::f
; // FIXME: this should fail.
1058 namespace cwg169
{ // cwg169: yes
1059 template<typename
> struct A
{ int n
; };
1061 template<typename
> struct C
;
1062 template<typename
> void f();
1063 template<typename
> static int n
;
1064 // cxx98-11-error@-1 {{variable templates are a C++14 extension}}
1066 struct D
: A
<int>, B
{
1069 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1071 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1073 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1077 namespace { // cwg171: 3.4
1080 int cwg171b
; // #cwg171b-int
1082 extern "C" void cwg171a();
1083 extern "C" void cwg171b();
1084 // expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}}
1085 // expected-note@#cwg171b-int {{declared in global scope here}}
1088 namespace cwg172
{ // cwg172: yes
1090 static_assert(-1 < zero
, "");
1092 enum { x
= -1, y
= (unsigned int)-1 };
1093 static_assert(sizeof(x
) > sizeof(int), "");
1095 enum { a
= (unsigned int)-1 / 2 };
1096 static_assert(sizeof(a
) == sizeof(int), "");
1097 static_assert(-a
< 0, "");
1099 enum { b
= (unsigned int)-1 / 2 + 1 };
1100 static_assert(sizeof(b
) == sizeof(unsigned int), "");
1101 static_assert(-b
> 0, "");
1103 enum { c
= (unsigned long)-1 / 2 };
1104 static_assert(sizeof(c
) == sizeof(long), "");
1105 static_assert(-c
< 0, "");
1107 enum { d
= (unsigned long)-1 / 2 + 1 };
1108 static_assert(sizeof(d
) == sizeof(unsigned long), "");
1109 static_assert(-d
> 0, "");
1111 enum { e
= (unsigned long long)-1 / 2 };
1112 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1113 static_assert(sizeof(e
) == sizeof(long), "");
1114 static_assert(-e
< 0, "");
1116 enum { f
= (unsigned long long)-1 / 2 + 1 };
1117 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1118 static_assert(sizeof(f
) == sizeof(unsigned long), "");
1119 static_assert(-f
> 0, "");
1122 namespace cwg173
{ // cwg173: yes
1123 static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
1124 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
1125 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', "");
1130 namespace cwg175
{ // cwg175: 2.8
1131 struct A
{}; // #cwg175-A
1132 struct B
: private A
{}; // #cwg175-B
1135 // expected-error@-1 {{'A' is a private member of 'cwg175::A'}}
1136 // expected-note@#cwg175-B {{constrained by private inheritance here}}
1137 // expected-note@#cwg175-A {{member is declared here}}
1142 namespace cwg176
{ // cwg176: 3.1
1143 template<typename T
> class Y
;
1144 template<> class Y
<int> {
1146 typedef Y A
; // #cwg176-A-first
1148 // expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}}
1149 // expected-note@#cwg176-A-first {{previous definition is here}}
1153 template<typename T
> struct Base
{}; // #cwg176-Base
1154 template<typename T
> struct Derived
: public Base
<T
> {
1156 typedef typename
Derived::template Base
<T
> A
;
1157 typedef typename
Derived::Base A
;
1160 template struct Derived
<int>;
1162 template<typename T
> struct Derived2
: Base
<int>, Base
<char> {
1163 typename
Derived2::Base b
;
1164 // expected-error@-1 {{member 'Base' found in multiple base classes of different types}}
1165 // expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}}
1166 // expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}}
1167 typename
Derived2::Base
<double> d
;
1170 template<typename T
> class X
{ // #cwg176-X
1174 cwg176::X
*p4
; // #cwg176-p4
1175 // cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}}
1176 // cxx98-14-note@#cwg176-X {{template is declared here}}
1177 // since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}}
1178 // since-cxx17-note@#cwg176-X {{template is declared here}}
1182 namespace cwg177
{ // cwg177: yes
1185 A(A
&); // #cwg177-A-copy-ctor
1186 A(const B
&); // #cwg177-A-ctor-from-B
1190 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}}
1191 // cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1192 // cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}}
1194 struct C
{ C(C
&); }; // #cwg177-C-copy-ctor
1196 struct E
{ operator D(); };
1199 // expected-error@-1 {{no viable constructor copying variable of type 'D'}}
1200 // expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1203 namespace cwg178
{ // cwg178: yes
1204 static_assert(int() == 0, "");
1205 #if __cplusplus >= 201103L
1206 static_assert(int{} == 0, "");
1207 struct S
{ int a
, b
; };
1208 static_assert(S
{1}.b
== 0, "");
1209 struct T
{ constexpr T() : n() {} int n
; };
1210 static_assert(T().n
== 0, "");
1211 struct U
: S
{ constexpr U() : S() {} };
1212 static_assert(U().b
== 0, "");
1216 namespace cwg179
{ // cwg179: yes
1219 // expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}}
1222 namespace cwg180
{ // cwg180: 2.8
1223 template<typename T
> struct X
: T
, T::some_base
{
1224 X() : T::some_type_that_might_be_T(), T::some_base() {}
1225 friend class T::some_class
;
1227 enum T::some_enum e
;
1232 namespace cwg181
{ // cwg181: yes
1234 template <template X
<class T
> > struct A
{ };
1235 // expected-error@-1 +{{}}
1236 template <template X
<class T
> > void f(A
<X
>) { }
1237 // expected-error@-1 +{{}}
1241 template <template <class T
> class X
> struct A
{ };
1242 template <template <class T
> class X
> void f(A
<X
>) { }
1246 namespace cwg182
{ // cwg182: 14
1247 template <class T
> struct C
{
1252 template <class T
> void C
<T
>::f() {}
1253 template <class T
> void C
<T
>::g() {}
1260 template void C
<A::B
>::f();
1261 template <> void C
<A::B
>::g();
1269 namespace cwg183
{ // cwg183: sup 382
1270 template<typename T
> struct A
{};
1271 template<typename T
> struct B
{
1274 template<> struct A
<int> {
1275 typename B
<int>::X x
;
1276 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1280 namespace cwg184
{ // cwg184: yes
1281 template<typename T
= float> struct B
{};
1283 template<template<typename TT
= float> class T
> struct A
{
1288 template<template<typename TT
> class T
> void A
<T
>::f() { // #cwg184-T
1290 // expected-error@-1 {{too few template arguments for template template parameter 'T'}}
1291 // expected-note@#cwg184-T {{template is declared here}}
1294 template<template<typename TT
= char> class T
> void A
<T
>::g() {
1300 void h() { A
<B
>().g(); }
1303 // cwg185 is in cwg185.cpp
1305 namespace cwg187
{ // cwg187: sup 481
1307 template<int X
= Z
, int Z
= X
> struct A
;
1312 namespace cwg188
{ // cwg188: yes
1314 static_assert(sizeof(0, c
) == 10, "");
1317 // cwg190 FIXME: add codegen test for tbaa
1318 // or implement C++20 std::is_layout_compatible and test it this way
1321 namespace cwg191
{ // cwg191: yes
1322 namespace example1
{
1337 namespace example2
{
1350 // cwg193 is in cwg193.cpp
1352 namespace cwg194
{ // cwg194: yes
1356 // expected-error@-1 {{constructor cannot have a return type}}
1360 // expected-error@-1 {{constructor cannot have a return type}}
1364 inline explicit C(int) {}
1368 namespace cwg195
{ // cwg195: yes
1371 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1372 void (*q
)() = (void(*)())&p
;
1373 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1376 namespace cwg197
{ // cwg197: yes
1379 template <class T
> void g(T t
) {
1382 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1383 // expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}}
1385 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1396 g(e
); // #cwg197-g-e-call
1400 namespace cwg198
{ // cwg198: yes
1405 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1406 int f() { return n
; }
1407 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1414 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1415 int f() { return n
; }
1416 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1420 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1421 int f() { return n
; }
1425 // cwg199 is in cwg199.cpp