// 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 // 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 // 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 // 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 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors #if __cplusplus == 199711L #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) // cxx98-error@-1 {{variadic macros are a C99 feature}} #endif #if __cplusplus == 199711L #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x)) #else #define __enable_constant_folding #endif namespace cwg100 { // cwg100: 2.7 template struct A {}; // #cwg100-A template struct B {}; // #cwg100-B template struct C {}; // #cwg100-C template struct D {}; // #cwg100-D A<&"foo"> a; // #cwg100-a // cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}} // cxx98-14-note@#cwg100-A {{template parameter is declared here}} // since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}} B<"bar"> b; // #cwg100-b // cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}} // cxx98-14-note@#cwg100-B {{template parameter is declared here}} // since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}} C<"baz"> c; // #cwg100-c // cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}} // cxx98-14-note@#cwg100-C {{template parameter is declared here}} // since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}} D<*"quux"> d; // #cwg100-d // cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}} // cxx98-14-note@#cwg100-D {{template parameter is declared here}} // since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}} } // namespace cwg100 namespace cwg101 { // cwg101: 3.5 extern "C" void cwg101_f(); typedef unsigned size_t; namespace X { extern "C" void cwg101_f(); typedef unsigned size_t; } using X::cwg101_f; using X::size_t; extern "C" void cwg101_f(); typedef unsigned size_t; } // namespace cwg101 namespace cwg102 { // cwg102: 2.7 namespace A { template T f(T a, T b) { return a + b; } // expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}} // expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f' requested here}} // expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}} } namespace B { struct S {}; } B::S operator+(B::S, B::S); // #cwg102-operator-plus template B::S A::f(B::S, B::S); // #cwg102-instantiation } // namespace cwg102 // cwg103: na // cwg104: na lib // cwg105: na namespace cwg106 { // cwg106: sup 540 typedef int &r1; typedef r1 &r1; typedef const r1 r1; // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} typedef const r1 &r1; // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} typedef const int &r2; typedef r2 &r2; typedef const r2 r2; // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} typedef const r2 &r2; // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} } // namespace cwg106 namespace cwg107 { // cwg107: 2.7 struct S {}; extern "C" S operator+(S, S) { return S(); } } // namespace cwg107 namespace cwg108 { // cwg108: 2.9 template struct A { struct B { typedef int X; }; B::X x; // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B::X' is a C++20 extension}} struct C : B { X x; }; // expected-error@-1 {{unknown type name 'X'}} }; template<> struct A::B { int X; }; } // namespace cwg108 namespace cwg109 { // cwg109: 2.8 struct A { template void f(T); }; template struct B : T { using T::template f; // expected-error@-1 {{'template' keyword not permitted here}} using T::template f; // expected-error@-1 {{'template' keyword not permitted here}} // expected-error@-2 {{using declaration cannot refer to a template specialization}} // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid. using T::f; // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} // expected-error@-2 {{using declaration cannot refer to a template specialization}} void g() { this->f(123); } // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} }; } // namespace cwg109 namespace cwg110 { // cwg110: 2.8 template void f(T); class f {}; template void f(T, T); class f g; void (*h)(int) = static_cast(f); void (*i)(int, int) = static_cast(f); } // namespace cwg110 namespace cwg111 { // cwg111: dup 535 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); }; struct B : A { B(); }; // #cwg111-B const B b1; B b2(b1); // expected-error@-1 {{no matching constructor for initialization of 'B'}} // expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}} // expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} } // namespace cwg111 namespace cwg112 { // cwg112: 3.1 struct T { int n; }; typedef T Arr[1]; const T a1[1] = {}; // #cwg112-a1 volatile T a2[1] = {}; const Arr a3 = {}; // #cwg112-a3 volatile Arr a4 = {}; template struct X {}; // FIXME: Test this somehow in C++11 and on. X x1; // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}} // cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}} X x2; X x3; // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}} // cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}} X x4; } // namespace cwg112 namespace cwg113 { // cwg113: 2.7 extern void (*p)(); void f() { no_such_function(); // expected-error@-1 {{use of undeclared identifier 'no_such_function'}} p(); } void g(); void (*p)() = &g; } // namespace cwg113 namespace cwg114 { // cwg114: 2.7 struct A { virtual void f(int) = 0; // #cwg114-A-f }; struct B : A { template void f(T); void g() { f(0); } } b; // expected-error@-1 {{variable type 'struct B' is an abstract class}} // expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}} } // namespace cwg114 namespace cwg115 { // cwg115: 3.0 template int f(T); // #cwg115-f template int g(T); // #cwg115-g template int g(T, int); // #cwg115-g-int int k1 = f(&f); // expected-error@-1 {{no matching function for call to 'f'}} // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} int k2 = f(&f); int k3 = f(&g); // expected-error@-1 {{no matching function for call to 'f'}} // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} void h() { (void)&f; // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}} // expected-note@#cwg115-f {{candidate function template}} (void)&f; (void)&g; // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}} // expected-note@#cwg115-g-int {{candidate function template}} // expected-note@#cwg115-g {{candidate function template}} &f; // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} // expected-note@#cwg115-f {{possible target for call}} &f; // expected-warning@-1 {{expression result unused}} &g; // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} // expected-note@#cwg115-g-int {{possible target for call}} // expected-note@#cwg115-g {{possible target for call}} } struct S { template static int f(T); template static int g(T); template static int g(T, int); } s; int k4 = f(&s.f); // expected-error@-1 {{cannot create a non-constant pointer to member function}} int k5 = f(&s.f); int k6 = f(&s.g); // expected-error@-1 {{cannot create a non-constant pointer to member function}} void i() { (void)&s.f; // expected-error@-1 {{cannot create a non-constant pointer to member function}} (void)&s.f; (void)&s.g; // expected-error@-1 {{cannot create a non-constant pointer to member function}} &s.f; // expected-error@-1 {{cannot create a non-constant pointer to member function}} &s.f; // expected-warning@-1 {{expression result unused}} &s.g; // expected-error@-1 {{cannot create a non-constant pointer to member function}} } struct T { template int f(T); template int g(T); template int g(T, int); } t; int k7 = f(&s.f); // expected-error@-1 {{cannot create a non-constant pointer to member function}} int k8 = f(&s.f); int k9 = f(&s.g); // expected-error@-1 {{cannot create a non-constant pointer to member function}} void j() { (void)&s.f; // expected-error@-1 {{cannot create a non-constant pointer to member function}} (void)&s.f; (void)&s.g; // expected-error@-1 {{cannot create a non-constant pointer to member function}} &s.f; // expected-error@-1 {{cannot create a non-constant pointer to member function}} &s.f; // expected-warning@-1 {{expression result unused}} &s.g; // expected-error@-1 {{cannot create a non-constant pointer to member function}} } #if __cplusplus >= 201103L // Special case kicks in only if a template argument list is specified. template void with_default(); // #cwg115-with-default int k10 = f(&with_default); // since-cxx11-error@-1 {{no matching function for call to 'f'}} // since-cxx11-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} int k11 = f(&with_default<>); void k() { (void)&with_default; // since-cxx11-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}} // since-cxx11-note@#cwg115-with-default {{candidate function template}} (void)&with_default<>; &with_default; // since-cxx11-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} // since-cxx11-note@#cwg115-with-default {{possible target for call}} &with_default<>; // since-cxx11-warning@-1 {{expression result unused}} } #endif } // namespace cwg115 namespace cwg116 { // cwg116: 2.7 template struct A {}; template void f(A) {} // #cwg116-f-N template void f(A) {} // expected-error@-1 {{redefinition of 'f'}} // expected-note@#cwg116-f-N {{previous definition is here}} template void f(A) {} // #cwg116-f-T template void f(A) {} // expected-error@-1 {{redefinition of 'f'}} // expected-note@#cwg116-f-T {{previous definition is here}} } // namespace cwg116 // cwg117: na // cwg118 is in cwg118.cpp // cwg119: na // cwg120: na namespace cwg121 { // cwg121: 2.7 struct X { template struct Y {}; }; template struct Z { X::Y x; T::Y y; // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}} // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name 'T::Y' is a C++20 extension}} }; Z z; } // namespace cwg121 namespace cwg122 { // cwg122: 2.7 template void f(); void g() { f(); } } // namespace cwg122 // cwg123: na // cwg124 is in cwg124.cpp // cwg125: 2.7 struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B cwg125_A::cwg125_B cwg125_C(); namespace cwg125_B { cwg125_A cwg125_C(); } namespace cwg125 { struct X { friend cwg125_A::cwg125_B (::cwg125_C)(); // ok friend cwg125_A (::cwg125_B::cwg125_C)(); // ok friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}} // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}} // cxx98-note@#cwg125_B {{previous declaration is here}} // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}} // since-cxx11-note@#cwg125_B {{previous declaration is here}} }; } // namespace cwg125 namespace cwg126 { // cwg126: partial // FIXME: We do not yet generate correct code for this change: // eg: // catch (void*&) should catch void* but not int* // catch (void*) and catch (void*const&) should catch both // Likewise: // catch (Base *&) should catch Base* but not Derived* // catch (Base *) should catch both // In each case, we emit the same code for both catches. // // The ABI does not let us represent the language rule in the unwind tables. // So, when catching by non-const (or volatile) reference to pointer, we // should compare the exception type to the caught type and only accept an // exact match. struct C {}; struct D : C {}; struct E : private C { friend class A; friend class B; }; struct F : protected C {}; struct G : C {}; struct H : D, G {}; #if __cplusplus <= 201402L struct A { virtual void cp() throw(C*); virtual void dp() throw(C*); virtual void ep() throw(C*); // #cwg126-ep virtual void fp() throw(C*); // #cwg126-fp virtual void gp() throw(C*); virtual void hp() throw(C*); // #cwg126-hp virtual void cr() throw(C&); virtual void dr() throw(C&); virtual void er() throw(C&); // #cwg126-er virtual void fr() throw(C&); // #cwg126-fr virtual void gr() throw(C&); virtual void hr() throw(C&); // #cwg126-hr virtual void pv() throw(void*); virtual void np() throw(C*); virtual void npm() throw(int C::*); virtual void nr() throw(C*&); // #cwg126-nr virtual void ncr() throw(C*const&); virtual void ref1() throw(C *const&); virtual void ref2() throw(C *); virtual void v() throw(int); virtual void w() throw(const int); virtual void x() throw(int*); // #cwg126-x virtual void y() throw(const int*); virtual void z() throw(int); // #cwg126-z }; struct B : A { virtual void cp() throw(C*); virtual void dp() throw(D*); virtual void ep() throw(E*); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-ep {{overridden virtual function is here}} virtual void fp() throw(F*); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-fp {{overridden virtual function is here}} virtual void gp() throw(G*); virtual void hp() throw(H*); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-hp {{overridden virtual function is here}} virtual void cr() throw(C&); virtual void dr() throw(D&); virtual void er() throw(E&); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-er {{overridden virtual function is here}} virtual void fr() throw(F&); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-fr {{overridden virtual function is here}} virtual void gr() throw(G&); virtual void hr() throw(H&); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-hr {{overridden virtual function is here}} virtual void pv() throw(C*); #if __cplusplus >= 201103L using nullptr_t = decltype(nullptr); virtual void np() throw(nullptr_t); virtual void npm() throw(nullptr_t&); virtual void nr() throw(nullptr_t); // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx11-14-note@#cwg126-nr {{overridden virtual function is here}} virtual void ncr() throw(nullptr_t); #endif // __cplusplus >= 201103L virtual void ref1() throw(D *const &); virtual void ref2() throw(D *); virtual void v() throw(const int); virtual void w() throw(int); virtual void x() throw(const int*); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-x {{overridden virtual function is here}} virtual void y() throw(int*); // ok virtual void z() throw(long); // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} // cxx98-14-note@#cwg126-z {{overridden virtual function is here}} }; #endif // __cplusplus <= 201402L void f() throw(int); // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} // since-cxx17-note@-2 {{use 'noexcept(false)' instead}} } // namespace cwg126 namespace cwg127 { // cwg127: 2.9 __extension__ typedef __decltype(sizeof(0)) size_t; template struct A { A() { throw 0; } void *operator new(size_t, const char * = 0); void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}} // expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A::operator delete' requested here}} // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}} // expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A::operator delete' requested here}} void operator delete(void *) { T::error; } }; A *p = new A; // #cwg127-p A *q = new ("") A; // #cwg127-q } // namespace cwg127 namespace cwg128 { // cwg128: 2.7 enum E1 { e1 } x = e1; enum E2 { e2 } y = static_cast(x), z = static_cast(e1); } // namespace cwg128 // cwg129: dup 616 // cwg130: na namespace cwg131 { // cwg131: sup P1949 const char *a_with_\u0e8c = "\u0e8c"; const char *b_with_\u0e8d = "\u0e8d"; const char *c_with_\u0e8e = "\u0e8e"; } // namespace cwg131 namespace cwg132 { // cwg132: no void f() { extern struct {} x; // ok extern struct S {} y; // FIXME: This is invalid. } static enum { E } e; } // namespace cwg132 // cwg133: dup 87 // cwg134: na namespace cwg135 { // cwg135: 2.7 struct A { A f(A a) { return a; } friend A g(A a) { return a; } static A h(A a) { return a; } }; } // namespace cwg135 namespace cwg136 { // cwg136: 3.4 void f(int, int, int = 0); // #cwg136-f void g(int, int, int); // #cwg136-g struct A { friend void f(int, int = 0, int); // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-f {{previous declaration is here}} friend void g(int, int, int = 0); // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-g {{previous declaration is here}} friend void h(int, int, int = 0); // expected-error@-1 {{friend declaration specifying a default argument must be a definition}} friend void i(int, int, int = 0) {} // #cwg136-A-i friend void j(int, int, int = 0) {} operator int(); }; void i(int, int, int); // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-A-i {{previous declaration is here}} void q() { j(A(), A()); // ok, has default argument } extern "C" void k(int, int, int, int); // #cwg136-k namespace NSA { struct A { friend void cwg136::k(int, int, int, int = 0); // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-k {{previous declaration is here}} }; } namespace NSB { struct A { friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-k {{previous declaration is here}} // expected-error@#cwg136-friend-k {{missing default argument on parameter}} }; } struct B { void f(int); // #cwg136-B-f }; struct C { friend void B::f(int = 0); // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} // expected-note@#cwg136-B-f {{previous declaration is here}} }; } // namespace cwg136 namespace cwg137 { // cwg137: 2.7 extern void *p; extern const void *cp; extern volatile void *vp; extern const volatile void *cvp; int *q = static_cast(p); int *qc = static_cast(cp); // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}} int *qv = static_cast(vp); // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}} int *qcv = static_cast(cvp); // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}} const int *cq = static_cast(p); const int *cqc = static_cast(cp); const int *cqv = static_cast(vp); // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}} const int *cqcv = static_cast(cvp); // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}} const volatile int *cvq = static_cast(p); const volatile int *cvqc = static_cast(cp); const volatile int *cvqv = static_cast(vp); const volatile int *cvqcv = static_cast(cvp); } // namespace cwg137 namespace cwg138 { // cwg138: partial namespace example1 { void foo(); // #cwg138-ex1-foo namespace A { using example1::foo; // #cwg138-ex1-using class X { static const int i = 10; // This friend declaration is using neither qualified-id nor template-id, // so name 'foo' is not looked up, which means the using-declaration has no effect. // Target scope of this declaration is A, so this is grating friendship to // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to. // A::foo corresponds to example1::foo named by the using declaration, // and since A::foo is a different entity, they potentially conflict. // FIXME: This is ill-formed, but not for the reason diagnostic says. friend void foo(); // expected-error@-1 {{cannot befriend target of using declaration}} // expected-note@#cwg138-ex1-foo {{target of using declaration}} // expected-note@#cwg138-ex1-using {{using declaration}} }; } } // namespace example1 namespace example2 { void f(); void g(); class B { void g(); }; class A : public B { static const int i = 10; void f(); // Both friend declaration are not using qualified-ids or template-ids, // so 'f' and 'g' are not looked up, which means that presence of A::f // and base B have no effect. // Both target scope of namespace 'example2', and grant friendship to // example2::f and example2::g respectively. friend void f(); friend void g(); }; void f() { int i2 = A::i; } void g() { int i3 = A::i; } } // namespace example2 namespace example3 { struct Base { private: static const int i = 10; // #cwg138-ex3-Base-i public: struct Data; // Elaborated type specifier is not the sole constituent of declaration, // so 'Data' undergoes unqualified type-only lookup, which finds Base::Data. friend class Data; struct Data { void f() { int i2 = Base::i; } }; }; struct Data { void f() { int i2 = Base::i; // expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}} // expected-note@#cwg138-ex3-Base-i {{declared private here}} } }; } // namespace example3 } // namespace cwg138 namespace cwg139 { // cwg139: 2.7 namespace example1 { typedef int f; // #cwg139-typedef-f struct A { friend void f(A &); // expected-error@-1 {{redefinition of 'f' as different kind of symbol}} // expected-note@#cwg139-typedef-f {{previous definition is here}} }; } namespace example2 { typedef int f; namespace N { struct A { friend void f(A &); operator int(); void g(A a) { int i = f(a); } // ok, f is typedef not friend function }; } } } // namespace cwg139 namespace cwg140 { // cwg140: 2.7 void f(int *const) {} // #cwg140-f-first void f(int[3]) {} // expected-error@-1 {{redefinition of 'f'}} // expected-note@#cwg140-f-first {{previous definition is here}} void g(const int); void g(int n) { n = 2; } } // namespace cwg140 namespace cwg141 { // cwg141: 3.1 template void f(); template struct S { int n; }; // #cwg141-S struct A : S { template void f(); template struct S {}; // #cwg141-A-S } a; struct B : S {} b; void g() { a.f(); (void)a.S::n; // #cwg141-a // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}} // cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}} // cxx98-note@#cwg141-S {{lookup from the current scope refers here}} // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S'}} // FIXME: we issue a useful diagnostic first, then some bogus ones. b.f(); // expected-error@-1 {{no member named 'f' in 'cwg141::B'}} // expected-error@-2 +{{}} (void)b.S::n; } template struct C { T t; void g() { t.f(); // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} } void h() { (void)t.S::n; // ok } void i() { (void)t.S(); // ok! } }; void h() { C().h(); } // ok struct X { template void S(); }; void i() { C().i(); } // ok!! } // namespace cwg141 namespace cwg142 { // cwg142: 2.8 class B { // #cwg142-B public: int mi; // #cwg142-B-mi static int si; // #cwg142-B-si }; class D : private B { // #cwg142-D }; class DD : public D { void f(); }; void DD::f() { mi = 3; // expected-error@-1 {{'mi' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B-mi {{member is declared here}} si = 3; // expected-error@-1 {{'si' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B-si {{member is declared here}} B b_old; // expected-error@-1 {{'B' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B {{member is declared here}} cwg142::B b; b.mi = 3; b.si = 3; B::si = 3; // expected-error@-1 {{'B' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B {{member is declared here}} cwg142::B::si = 3; B *bp1_old = this; // #cwg142-bp1_old // expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B {{member is declared here}} // expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}} // expected-note@#cwg142-D {{declared private here}} cwg142::B *bp1 = this; // expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}} // expected-note@#cwg142-D {{declared private here}} B *bp2_old = (B*)this; // #cwg142-bp2_old // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B {{member is declared here}} // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} // expected-note@#cwg142-D {{constrained by private inheritance here}} // expected-note@#cwg142-B {{member is declared here}} cwg142::B *bp2 = (cwg142::B*)this; bp2->mi = 3; } } // namespace cwg142 namespace cwg143 { // cwg143: 2.7 namespace A { struct X; } namespace B { void f(A::X); } namespace A { struct X { friend void B::f(X); }; } void g(A::X x) { f(x); // expected-error@-1 {{use of undeclared identifier 'f'}} } } // namespace cwg143 namespace cwg145 { // cwg145: 2.7 void f(bool b) { ++b; // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} b++; // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} } } // namespace cwg145 namespace cwg147 { // cwg147: 2.7 namespace example1 { template struct A { template A(T); }; // Per core issue 1435, this is ill-formed because A::A does not // name the injected-class-name. (A::A does, though.) template<> template<> A::A(int) {} // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}} template<> template<> A::A(float) {} } namespace example2 { struct A { A(); }; struct B : A { B(); }; A::A a1; // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}} B::A a2; } namespace example3 { template struct A { template A(T); static A a; }; template<> A::A(A::a); // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}} } } // namespace cwg147 namespace cwg148 { // cwg148: 2.7 struct A { int A::*p; }; static_assert(__is_pod(int(A::*)), ""); static_assert(__is_pod(A), ""); } // namespace cwg148 // cwg149: na namespace cwg150 { // cwg150: 19 namespace p1 { template class ARG { }; template class PARM> void f(PARM) { } void g() { ARG x; f(x); } } // namespace p1 namespace p2 { template