brintos

brintos / llvm-project-archived public Read only

0
0
Text · 48.5 KiB · c9dce77 Raw
1472 lines · cpp
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-errors2// 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-errors3// 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-errors4// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors8 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14#if __cplusplus == 199711L15#define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))16#else17#define __enable_constant_folding18#endif19 20namespace cwg100 { // cwg100: 2.721  template<const char (*)[4]> struct A {}; // #cwg100-A22  template<const char (&)[4]> struct B {}; // #cwg100-B23  template<const char *> struct C {}; // #cwg100-C24  template<const char &> struct D {}; // #cwg100-D25  A<&"foo"> a; // #cwg100-a26  // cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}}27  //   cxx98-14-note@#cwg100-A {{template parameter is declared here}}28  // since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}}29  B<"bar"> b; // #cwg100-b30  // cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}}31  //   cxx98-14-note@#cwg100-B {{template parameter is declared here}}32  // since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}}33  C<"baz"> c; // #cwg100-c34  // cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}}35  //   cxx98-14-note@#cwg100-C {{template parameter is declared here}}36  // since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}}37  D<*"quux"> d; // #cwg100-d38  // cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}}39  //   cxx98-14-note@#cwg100-D {{template parameter is declared here}}40  // since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}}41} // namespace cwg10042 43namespace cwg101 { // cwg101: 3.544  extern "C" void cwg101_f();45  typedef unsigned size_t;46  namespace X {47    extern "C" void cwg101_f();48    typedef unsigned size_t;49  }50  using X::cwg101_f;51  using X::size_t;52  extern "C" void cwg101_f();53  typedef unsigned size_t;54} // namespace cwg10155 56namespace cwg102 { // cwg102: 2.757  namespace A {58    template<typename T> T f(T a, T b) { return a + b; }59    // expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}60    //   expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f<cwg102::B::S>' requested here}}61    //   expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}}62  }63  namespace B {64    struct S {};65  }66  B::S operator+(B::S, B::S); // #cwg102-operator-plus67  template B::S A::f(B::S, B::S); // #cwg102-instantiation68} // namespace cwg10269 70// cwg103: na71// cwg104: na lib72// cwg105: na73 74namespace cwg106 { // cwg106: sup 54075  typedef int &r1;76  typedef r1 &r1;77  typedef const r1 r1;78  // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}79  typedef const r1 &r1;80  // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}81 82  typedef const int &r2;83  typedef r2 &r2;84  typedef const r2 r2;85  // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}86  typedef const r2 &r2;87  // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}88} // namespace cwg10689 90namespace cwg107 { // cwg107: 2.791  struct S {};92  extern "C" S operator+(S, S) { return S(); }93} // namespace cwg10794 95namespace cwg108 { // cwg108: 2.996  template<typename T> struct A {97    struct B { typedef int X; };98    B::X x;99    // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B::X' is a C++20 extension}}100    struct C : B { X x; };101    // expected-error@-1 {{unknown type name 'X'}}102  };103  template<> struct A<int>::B { int X; };104} // namespace cwg108105 106namespace cwg109 { // cwg109: 2.8107  struct A { template<typename T> void f(T); };108  template<typename T> struct B : T {109    using T::template f;110    // expected-error@-1 {{'template' keyword not permitted here}}111    using T::template f<int>;112    // expected-error@-1 {{'template' keyword not permitted here}}113    // expected-error@-2 {{using declaration cannot refer to a template specialization}}114    // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.115    using T::f<int>;116    // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}117    // expected-error@-2 {{using declaration cannot refer to a template specialization}}118    void g() { this->f<int>(123); }119    // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}120  };121} // namespace cwg109122 123namespace cwg110 { // cwg110: 2.8124template <typename T>125void f(T);126 127class f {};128 129template <typename T>130void f(T, T);131 132class f g;133void (*h)(int) = static_cast<void(*)(int)>(f);134void (*i)(int, int) = static_cast<void(*)(int, int)>(f);135} // namespace cwg110136 137namespace cwg111 { // cwg111: dup 535138  struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };139  struct B : A { B(); }; // #cwg111-B140  const B b1;141  B b2(b1);142  // expected-error@-1 {{no matching constructor for initialization of 'B'}}143  //   expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}}144  //   expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}145} // namespace cwg111146 147namespace cwg112 { // cwg112: 3.1148  struct T { int n; };149  typedef T Arr[1];150 151  const T a1[1] = {}; // #cwg112-a1152  volatile T a2[1] = {};153  const Arr a3 = {}; // #cwg112-a3154  volatile Arr a4 = {};155  template<const volatile T*> struct X {};156  // FIXME: Test this somehow in C++11 and on.157  X<a1> x1;158  // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}}159  //   cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}}160  X<a2> x2;161  X<a3> x3;162  // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}}163  //   cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}}164  X<a4> x4;165} // namespace cwg112166 167namespace cwg113 { // cwg113: 2.7168  extern void (*p)();169  void f() {170    no_such_function();171    // expected-error@-1 {{use of undeclared identifier 'no_such_function'}}172    p();173  }174  void g();175  void (*p)() = &g;176} // namespace cwg113177 178namespace cwg114 { // cwg114: 2.7179  struct A {180    virtual void f(int) = 0; // #cwg114-A-f181  };182  struct B : A {183    template<typename T> void f(T);184    void g() { f(0); }185  } b;186  // expected-error@-1 {{variable type 'struct B' is an abstract class}}187  //   expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}}188} // namespace cwg114189 190namespace cwg115 { // cwg115: 3.0191  template<typename T> int f(T); // #cwg115-f192  template<typename T> int g(T); // #cwg115-g193  template<typename T> int g(T, int); // #cwg115-g-int194 195  int k1 = f(&f);196  // expected-error@-1 {{no matching function for call to 'f'}}197  //   expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}198  int k2 = f(&f<int>);199  int k3 = f(&g<int>);200  // expected-error@-1 {{no matching function for call to 'f'}}201  //   expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}202 203  void h() {204    (void)&f;205    // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}}206    //   expected-note@#cwg115-f {{candidate function template}}207    (void)&f<int>;208    (void)&g<int>;209    // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}}210    //   expected-note@#cwg115-g-int {{candidate function template}}211    //   expected-note@#cwg115-g {{candidate function template}}212 213    &f;214    // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}215    //   expected-note@#cwg115-f {{possible target for call}}216    &f<int>;217    // expected-warning@-1 {{expression result unused}}218    &g<int>;219    // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}220    //   expected-note@#cwg115-g-int {{possible target for call}}221    //   expected-note@#cwg115-g {{possible target for call}}222  }223 224  struct S {225    template<typename T> static int f(T);226    template<typename T> static int g(T);227    template<typename T> static int g(T, int);228  } s;229 230  int k4 = f(&s.f);231  // expected-error@-1 {{cannot create a non-constant pointer to member function}}232  int k5 = f(&s.f<int>);233  int k6 = f(&s.g<int>);234  // expected-error@-1 {{cannot create a non-constant pointer to member function}}235 236  void i() {237    (void)&s.f;238    // expected-error@-1 {{cannot create a non-constant pointer to member function}}239    (void)&s.f<int>;240    (void)&s.g<int>;241    // expected-error@-1 {{cannot create a non-constant pointer to member function}}242 243    &s.f;244    // expected-error@-1 {{cannot create a non-constant pointer to member function}}245    &s.f<int>;246    // expected-warning@-1 {{expression result unused}}247    &s.g<int>;248    // expected-error@-1 {{cannot create a non-constant pointer to member function}}249  }250 251  struct T {252    template<typename T> int f(T);253    template<typename T> int g(T);254    template<typename T> int g(T, int);255  } t;256 257  int k7 = f(&s.f);258  // expected-error@-1 {{cannot create a non-constant pointer to member function}}259  int k8 = f(&s.f<int>);260  int k9 = f(&s.g<int>);261  // expected-error@-1 {{cannot create a non-constant pointer to member function}}262 263  void j() {264    (void)&s.f;265    // expected-error@-1 {{cannot create a non-constant pointer to member function}}266    (void)&s.f<int>;267    (void)&s.g<int>;268    // expected-error@-1 {{cannot create a non-constant pointer to member function}}269 270    &s.f;271    // expected-error@-1 {{cannot create a non-constant pointer to member function}}272    &s.f<int>;273    // expected-warning@-1 {{expression result unused}}274    &s.g<int>;275    // expected-error@-1 {{cannot create a non-constant pointer to member function}}276  }277 278#if __cplusplus >= 201103L279  // Special case kicks in only if a template argument list is specified.280  template<typename T=int> void with_default(); // #cwg115-with-default281  int k10 = f(&with_default);282  // since-cxx11-error@-1 {{no matching function for call to 'f'}}283  //   since-cxx11-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}284  int k11 = f(&with_default<>);285  void k() {286    (void)&with_default;287    // since-cxx11-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}}288    //   since-cxx11-note@#cwg115-with-default {{candidate function template}}289    (void)&with_default<>;290    &with_default;291    // since-cxx11-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}292    //   since-cxx11-note@#cwg115-with-default {{possible target for call}}293    &with_default<>;294    // since-cxx11-warning@-1 {{expression result unused}}295  }296#endif297} // namespace cwg115298 299namespace cwg116 { // cwg116: 2.7300  template<int> struct A {};301  template<int N> void f(A<N>) {} // #cwg116-f-N302  template<int M> void f(A<M>) {}303  // expected-error@-1 {{redefinition of 'f'}}304  //   expected-note@#cwg116-f-N {{previous definition is here}}305  template<typename T> void f(A<sizeof(T)>) {} // #cwg116-f-T306  template<typename U> void f(A<sizeof(U)>) {}307  // expected-error@-1 {{redefinition of 'f'}}308  //   expected-note@#cwg116-f-T {{previous definition is here}}309} // namespace cwg116310 311// cwg117: na312// cwg118 is in cwg118.cpp313// cwg119: na314// cwg120: na315 316namespace cwg121 { // cwg121: 2.7317  struct X {318    template<typename T> struct Y {};319  };320  template<typename T> struct Z {321    X::Y<T> x;322    T::Y<T> y;323    // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}}324    // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name 'T::Y' is a C++20 extension}}325  };326  Z<X> z;327} // namespace cwg121328 329namespace cwg122 { // cwg122: 2.7330  template<typename T> void f();331  void g() { f<int>(); }332} // namespace cwg122333 334// cwg123: na335// cwg124 is in cwg124.cpp336 337// cwg125: 2.7338struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B339cwg125_A::cwg125_B cwg125_C();340namespace cwg125_B { cwg125_A cwg125_C(); }341namespace cwg125 {342  struct X {343    friend cwg125_A::cwg125_B (::cwg125_C)(); // ok344    friend cwg125_A (::cwg125_B::cwg125_C)(); // ok345    friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C346    // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}}347    // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}}348    //   cxx98-note@#cwg125_B {{previous declaration is here}}349    // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}}350    //   since-cxx11-note@#cwg125_B {{previous declaration is here}}351  };352} // namespace cwg125353 354namespace cwg126 { // cwg126: partial355  // FIXME: We do not yet generate correct code for this change:356  // eg:357  //   catch (void*&) should catch void* but not int*358  //   catch (void*) and catch (void*const&) should catch both359  // Likewise:360  //   catch (Base *&) should catch Base* but not Derived*361  //   catch (Base *) should catch both362  // In each case, we emit the same code for both catches.363  //364  // The ABI does not let us represent the language rule in the unwind tables.365  // So, when catching by non-const (or volatile) reference to pointer, we366  // should compare the exception type to the caught type and only accept an367  // exact match.368  struct C {};369  struct D : C {};370  struct E : private C { friend class A; friend class B; };371  struct F : protected C {};372  struct G : C {};373  struct H : D, G {};374 375#if __cplusplus <= 201402L376  struct A {377    virtual void cp() throw(C*);378    virtual void dp() throw(C*);379    virtual void ep() throw(C*); // #cwg126-ep380    virtual void fp() throw(C*); // #cwg126-fp381    virtual void gp() throw(C*);382    virtual void hp() throw(C*); // #cwg126-hp383 384    virtual void cr() throw(C&);385    virtual void dr() throw(C&);386    virtual void er() throw(C&); // #cwg126-er387    virtual void fr() throw(C&); // #cwg126-fr388    virtual void gr() throw(C&);389    virtual void hr() throw(C&); // #cwg126-hr390 391    virtual void pv() throw(void*);392 393    virtual void np() throw(C*);394    virtual void npm() throw(int C::*);395    virtual void nr() throw(C*&); // #cwg126-nr396    virtual void ncr() throw(C*const&);397 398    virtual void ref1() throw(C *const&);399    virtual void ref2() throw(C *);400 401    virtual void v() throw(int);402    virtual void w() throw(const int);403    virtual void x() throw(int*); // #cwg126-x404    virtual void y() throw(const int*);405    virtual void z() throw(int); // #cwg126-z406  };407  struct B : A {408    virtual void cp() throw(C*);409    virtual void dp() throw(D*);410    virtual void ep() throw(E*);411    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}412    //   cxx98-14-note@#cwg126-ep {{overridden virtual function is here}}413    virtual void fp() throw(F*);414    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}415    //   cxx98-14-note@#cwg126-fp {{overridden virtual function is here}}416    virtual void gp() throw(G*);417    virtual void hp() throw(H*);418    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}419    //   cxx98-14-note@#cwg126-hp {{overridden virtual function is here}}420 421    virtual void cr() throw(C&);422    virtual void dr() throw(D&);423    virtual void er() throw(E&);424    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}425    //   cxx98-14-note@#cwg126-er {{overridden virtual function is here}}426    virtual void fr() throw(F&);427    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}428    //   cxx98-14-note@#cwg126-fr {{overridden virtual function is here}}429    virtual void gr() throw(G&);430    virtual void hr() throw(H&);431    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}432    //   cxx98-14-note@#cwg126-hr {{overridden virtual function is here}}433 434    virtual void pv() throw(C*);435 436#if __cplusplus >= 201103L437    using nullptr_t = decltype(nullptr);438    virtual void np() throw(nullptr_t);439    virtual void npm() throw(nullptr_t&);440    virtual void nr() throw(nullptr_t);441    // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}}442    //   cxx11-14-note@#cwg126-nr {{overridden virtual function is here}}443    virtual void ncr() throw(nullptr_t);444#endif // __cplusplus >= 201103L445 446    virtual void ref1() throw(D *const &);447    virtual void ref2() throw(D *);448 449    virtual void v() throw(const int);450    virtual void w() throw(int);451    virtual void x() throw(const int*);452    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}453    //   cxx98-14-note@#cwg126-x {{overridden virtual function is here}}454    virtual void y() throw(int*); // ok455    virtual void z() throw(long);456    // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}457    //   cxx98-14-note@#cwg126-z {{overridden virtual function is here}}458  };459#endif // __cplusplus <= 201402L460  void f() throw(int);461  // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}462  //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}463} // namespace cwg126464 465namespace cwg127 { // cwg127: 2.9466  __extension__ typedef __decltype(sizeof(0)) size_t;467  template<typename T> struct A {468    A() { throw 0; }469    void *operator new(size_t, const char * = 0);470    void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char471    // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}}472    //   expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}}473    // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}}474    //   expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}}475    void operator delete(void *) { T::error; }476  };477  A<void> *p = new A<void>; // #cwg127-p478  A<int> *q = new ("") A<int>; // #cwg127-q479} // namespace cwg127480 481namespace cwg128 { // cwg128: 2.7482  enum E1 { e1 } x = e1;483  enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);484} // namespace cwg128485 486// cwg129: dup 616487// cwg130: na488 489namespace cwg131 { // cwg131: sup P1949490  const char *a_with_\u0e8c = "\u0e8c";491  const char *b_with_\u0e8d = "\u0e8d";492  const char *c_with_\u0e8e = "\u0e8e";493} // namespace cwg131494 495namespace cwg132 { // cwg132: no496  void f() {497    extern struct {} x; // ok498    extern struct S {} y; // FIXME: This is invalid.499  }500  static enum { E } e;501} // namespace cwg132502 503// cwg133: dup 87504// cwg134: na505 506namespace cwg135 { // cwg135: 2.7507  struct A {508    A f(A a) { return a; }509    friend A g(A a) { return a; }510    static A h(A a) { return a; }511  };512} // namespace cwg135513 514namespace cwg136 { // cwg136: 3.4515  void f(int, int, int = 0); // #cwg136-f516  void g(int, int, int); // #cwg136-g517  struct A {518    friend void f(int, int = 0, int);519    // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}520    //   expected-note@#cwg136-f {{previous declaration is here}}521    friend void g(int, int, int = 0);522    // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}523    //   expected-note@#cwg136-g {{previous declaration is here}}524    friend void h(int, int, int = 0);525    // expected-error@-1 {{friend declaration specifying a default argument must be a definition}}526    friend void i(int, int, int = 0) {} // #cwg136-A-i527    friend void j(int, int, int = 0) {}528    operator int();529  };530  void i(int, int, int);531  // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}532  //   expected-note@#cwg136-A-i {{previous declaration is here}}533  void q() {534    j(A(), A()); // ok, has default argument535  }536  extern "C" void k(int, int, int, int); // #cwg136-k537  namespace NSA {538  struct A {539    friend void cwg136::k(int, int, int, int = 0);540    // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}541    //   expected-note@#cwg136-k {{previous declaration is here}}542  };543  }544  namespace NSB {545  struct A {546    friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k547    // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}}548    //   expected-note@#cwg136-k {{previous declaration is here}}549    // expected-error@#cwg136-friend-k {{missing default argument on parameter}}550  };551  }552  struct B {553    void f(int); // #cwg136-B-f554  };555  struct C {556    friend void B::f(int = 0);557    // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}558    //   expected-note@#cwg136-B-f {{previous declaration is here}}559  };560} // namespace cwg136561 562namespace cwg137 { // cwg137: 2.7563  extern void *p;564  extern const void *cp;565  extern volatile void *vp;566  extern const volatile void *cvp;567  int *q = static_cast<int*>(p);568  int *qc = static_cast<int*>(cp);569  // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}}570  int *qv = static_cast<int*>(vp);571  // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}}572  int *qcv = static_cast<int*>(cvp);573  // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}}574  const int *cq = static_cast<const int*>(p);575  const int *cqc = static_cast<const int*>(cp);576  const int *cqv = static_cast<const int*>(vp);577  // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}}578  const int *cqcv = static_cast<const int*>(cvp);579  // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}}580  const volatile int *cvq = static_cast<const volatile int*>(p);581  const volatile int *cvqc = static_cast<const volatile int*>(cp);582  const volatile int *cvqv = static_cast<const volatile int*>(vp);583  const volatile int *cvqcv = static_cast<const volatile int*>(cvp);584} // namespace cwg137585 586namespace cwg138 { // cwg138: partial587namespace example1 {588void foo(); // #cwg138-ex1-foo589namespace A {590  using example1::foo; // #cwg138-ex1-using591  class X {592    static const int i = 10;593    // This friend declaration is using neither qualified-id nor template-id,594    // so name 'foo' is not looked up, which means the using-declaration has no effect.595    // Target scope of this declaration is A, so this is grating friendship to596    // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to.597    // A::foo corresponds to example1::foo named by the using declaration,598    // and since A::foo is a different entity, they potentially conflict.599    // FIXME: This is ill-formed, but not for the reason diagnostic says.600    friend void foo();601    // expected-error@-1 {{cannot befriend target of using declaration}}602    //   expected-note@#cwg138-ex1-foo {{target of using declaration}}603    //   expected-note@#cwg138-ex1-using {{using declaration}}604  };605}606} // namespace example1607 608namespace example2 {609void f();610void g();611class B {612  void g();613};614class A : public B {615  static const int i = 10;616  void f();617  // Both friend declaration are not using qualified-ids or template-ids,618  // so 'f' and 'g' are not looked up, which means that presence of A::f619  // and base B have no effect.620  // Both target scope of namespace 'example2', and grant friendship to621  // example2::f and example2::g respectively.622  friend void f();623  friend void g();624};625void f() {626  int i2 = A::i;627}628void g() {629  int i3 = A::i;630}631} // namespace example2632 633namespace example3 {634struct Base {635private:636  static const int i = 10; // #cwg138-ex3-Base-i637  638public:639  struct Data;640  // Elaborated type specifier is not the sole constituent of declaration,641  // so 'Data' undergoes unqualified type-only lookup, which finds Base::Data.642  friend class Data;643 644  struct Data {645    void f() {646      int i2 = Base::i;647    }648  };649};650struct Data {651  void f() {  652    int i2 = Base::i;653    // expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}}654    //   expected-note@#cwg138-ex3-Base-i {{declared private here}}655  }656};657} // namespace example3658} // namespace cwg138659 660namespace cwg139 { // cwg139: 2.7661  namespace example1 {662    typedef int f; // #cwg139-typedef-f663    struct A {664      friend void f(A &);665      // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}666      //   expected-note@#cwg139-typedef-f {{previous definition is here}}667    };668  }669 670  namespace example2 {671    typedef int f;672    namespace N {673      struct A {674        friend void f(A &);675        operator int();676        void g(A a) { int i = f(a); } // ok, f is typedef not friend function677      };678    }679  }680} // namespace cwg139681 682namespace cwg140 { // cwg140: 2.7683  void f(int *const) {} // #cwg140-f-first684  void f(int[3]) {}685  // expected-error@-1 {{redefinition of 'f'}}686  //   expected-note@#cwg140-f-first {{previous definition is here}}687  void g(const int);688  void g(int n) { n = 2; }689} // namespace cwg140690 691namespace cwg141 { // cwg141: 3.1692  template<typename T> void f();693  template<typename T> struct S { int n; }; // #cwg141-S694  struct A : S<int> {695    template<typename T> void f();696    template<typename T> struct S {}; // #cwg141-A-S697  } a;698  struct B : S<int> {} b;699  void g() {700    a.f<int>();701    (void)a.S<int>::n; // #cwg141-a702    // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}}703    //   cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}}704    //   cxx98-note@#cwg141-S {{lookup from the current scope refers here}}705    // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'}}706    // FIXME: we issue a useful diagnostic first, then some bogus ones.707    b.f<int>();708    // expected-error@-1 {{no member named 'f' in 'cwg141::B'}}709    // expected-error@-2 +{{}}710    (void)b.S<int>::n;711  }712  template<typename T> struct C {713    T t;714    void g() {715      t.f<int>();716      // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}717    }718    void h() {719      (void)t.S<int>::n; // ok720    }721    void i() {722      (void)t.S<int>(); // ok!723    }724  };725  void h() { C<B>().h(); } // ok726  struct X {727    template<typename T> void S();728  };729  void i() { C<X>().i(); } // ok!!730} // namespace cwg141731 732namespace cwg142 { // cwg142: 2.8733  class B { // #cwg142-B734  public:735    int mi; // #cwg142-B-mi736    static int si; // #cwg142-B-si737  };738  class D : private B { // #cwg142-D739  };740  class DD : public D {741    void f();742  };743  void DD::f() {744    mi = 3;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}}748    si = 3;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}}752    B b_old;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}}756    cwg142::B b;757    b.mi = 3;758    b.si = 3;759    B::si = 3;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}}763    cwg142::B::si = 3;764    B *bp1_old = this; // #cwg142-bp1_old765    // 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_old774    // 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;781    bp2->mi = 3;782  }783} // namespace cwg142784 785namespace cwg143 { // cwg143: 2.7786  namespace A { struct X; }787  namespace B { void f(A::X); }788  namespace A {789    struct X { friend void B::f(X); };790  }791  void g(A::X x) {792    f(x);793    // expected-error@-1 {{use of undeclared identifier 'f'}}794  }795} // namespace cwg143796 797namespace cwg145 { // cwg145: 2.7798  void f(bool b) {799    ++b;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}}802    b++;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}}805  }806} // namespace cwg145807 808namespace cwg147 { // cwg147: 2.7809  namespace example1 {810    template<typename> struct A {811      template<typename T> A(T);812    };813    // Per core issue 1435, this is ill-formed because A<int>::A<int> does not814    // 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) {}818  }819  namespace example2 {820    struct A { A(); };821    struct B : A { B(); };822    A::A a1;823    // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}}824    B::A a2;825  }826  namespace example3 {827    template<typename> struct A {828      template<typename T> A(T);829      static A a;830    };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}}833  }834} // namespace cwg147835 836namespace cwg148 { // cwg148: 2.7837  struct A { int A::*p; };838  static_assert(__is_pod(int(A::*)), "");839  static_assert(__is_pod(A), "");840} // namespace cwg148841 842// cwg149: na843 844namespace cwg150 { // cwg150: 19845  namespace p1 {846    template <class T, class U = int>847    class ARG { };848 849    template <class X, template <class Y> class PARM>850    void f(PARM<X>) { }851 852    void g() {853      ARG<int> x;854      f(x);855    }856  } // namespace p1857 858  namespace p2 {859    template <template <class T, class U = int> class PARM>860    class C {861      PARM<int> pi;862    };863  } // namespace p2864 865  namespace n1 {866    struct Dense { static const unsigned int dim = 1; };867 868    template <template <typename> class View,869              typename Block>870    void operator+(float, View<Block> const&);871 872    template <typename Block,873              unsigned int Dim = Block::dim>874    class Lvalue_proxy { operator float() const; };875 876    void test_1d (void) {877      Lvalue_proxy<Dense> p;878      float b;879      b + p;880    }881  } // namespace n1882} // namespace cwg150883 884namespace cwg151 { // cwg151: 3.1885  struct X {};886  typedef int X::*p;887  static_assert(__enable_constant_folding(p() == 0), "");888} // namespace cwg151889 890namespace cwg152 { // cwg152: 2.7891  struct A {892    A(); // #cwg152-A-ctor893    explicit A(const A&); // #cwg152-A-explicit-ctor894  };895  A a1 = A();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}}899  A a2((A()));900 901  A &f();902  A a3 = f();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}}906  A a4(f());907} // namespace cwg152908 909// cwg153: na910 911namespace cwg154 { // cwg154: 2.7912  union { int a; };913  // expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}}914  namespace {915    union { int b; };916  }917  static union { int c; };918} // namespace cwg154919 920namespace cwg155 { // cwg155: dup 632921  struct S { int n; } s = { { 1 } };922  // expected-warning@-1 {{braces around scalar initializer}}923} // namespace cwg155924 925// cwg156: sup 1111926// cwg158 is in cwg158.cpp927 928namespace cwg159 { // cwg159: 3.5929  namespace X { void f(); }930  void f();931  void cwg159::f() {}932  // expected-warning@-1 {{extra qualification on member 'f'}}933  void cwg159::X::f() {}934} // namespace cwg159935 936// cwg160: na937 938namespace cwg161 { // cwg161: 3.1939  class A {940  protected:941    struct B { int n; } b; // #cwg161-B942    static B bs;943    void f(); // #cwg161-f944    static void sf();945  };946  struct C : A {};947  struct D : A {948    void g(C c) {949      (void)b.n;950      B b1;951      C::B b2; // ok, accessible as a member of A952      (void)&C::b;953      // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}954      //   expected-note@#cwg161-B {{declared protected here}}955      (void)&C::bs;956      (void)c.b;957      // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}958      //   expected-note@#cwg161-B {{declared protected here}}959      (void)c.bs;960      f();961      sf();962      c.f();963      // expected-error@-1 {{protected}}964      //   expected-note@#cwg161-f {{declared protected here}}965      c.sf();966      A::f();967      D::f();968      A::sf();969      C::sf();970      D::sf();971    }972  };973} // namespace cwg161974 975namespace cwg162 { // cwg162: 19976  struct A {977    char &f(char);978    static int &f(int);979 980    void g() {981      int &a = (&A::f)(0);982      char &b = (&A::f)('0');983      // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}984    }985  };986 987  int &c = (&A::f)(0);988  char &d = (&A::f)('0');989  // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}990} // namespace cwg162991 992// cwg163: na993 994namespace cwg164 { // cwg164: 2.7995  void f(int);996  template <class T> int g(T t) { return f(t); }997 998  enum E { e };999  int f(E);1000 1001  int k = g(e);1002} // namespace cwg1641003 1004namespace cwg165 { // cwg165: no1005  namespace N {1006    struct A { friend struct B; };1007    void f() { void g(); }1008  }1009  // FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed1010  struct N::B {};1011  // FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok1012  void N::g() {}1013} // namespace cwg1651014 1015namespace cwg166 { // cwg166: 2.91016  namespace A { class X; }1017 1018  template<typename T> int f(T t) { return t.n; }1019  int g(A::X);1020  template<typename T> int h(T t) { return t.n; }1021  // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}1022  //   expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}}1023  //   expected-note@#cwg166-X-n {{implicitly declared private here}}1024  int i(A::X);1025 1026  namespace A {1027    class X {1028      friend int f<X>(X);1029      friend int cwg166::g(X);1030      friend int h(X);1031      friend int i(X);1032      int n; // #cwg166-X-n1033    };1034 1035    int h(X x) { return x.n; }1036    int i(X x) { return x.n; }1037  }1038 1039  template int f(A::X);1040  int g(A::X x) { return x.n; }1041  template int h(A::X); // #cwg166-h-instantiation1042  int i(A::X x) { return x.n; }1043  // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}1044  //   expected-note@#cwg166-X-n {{implicitly declared private here}}1045} // namespace cwg1661046 1047// cwg167: sup 10121048 1049namespace cwg168 { // cwg168: no1050  extern "C" typedef int (*p)();1051  extern "C++" typedef int (*q)();1052  struct S {1053    static int f();1054  };1055  p a = &S::f; // FIXME: this should fail.1056  q b = &S::f;1057} // namespace cwg1681058 1059namespace cwg169 { // cwg169: 3.41060  template<typename> struct A { int n; };1061  struct B {1062    template<typename> struct C;1063    template<typename> void f();1064    template<typename> static int n;1065    // cxx98-11-error@-1 {{variable templates are a C++14 extension}}1066  };1067  struct D : A<int>, B {1068    using A<int>::n;1069    using B::C<int>;1070    // expected-error@-1 {{using declaration cannot refer to a template specialization}}1071    using B::f<int>;1072    // expected-error@-1 {{using declaration cannot refer to a template specialization}}1073    using B::n<int>;1074    // expected-error@-1 {{using declaration cannot refer to a template specialization}}1075  };1076} // namespace cwg1691077 1078namespace cwg170 { // cwg170: 3.11079#if __cplusplus >= 201103L1080struct A {};1081struct B : A { int i; };1082struct C : A {};1083struct D : C {};1084 1085constexpr int f(int A::*) { return 0; }1086constexpr int g(int C::*) { return 0; }1087constexpr int h(int D::*) { return 0; }1088 1089constexpr auto p = static_cast<int A::*>(&B::i);1090constexpr auto q = f(p);1091constexpr auto r = g(p);1092// since-cxx11-error@-1 {{constexpr variable 'r' must be initialized by a constant expression}}1093constexpr auto s = h(p);1094// since-cxx11-error@-1 {{constexpr variable 's' must be initialized by a constant expression}}1095#endif1096} // namespace cwg1701097 1098namespace { // cwg171: 3.41099  int cwg171a;1100}1101int cwg171b; // #cwg171b-int1102namespace cwg171 {1103  extern "C" void cwg171a();1104  extern "C" void cwg171b();1105  // expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}}1106  //   expected-note@#cwg171b-int {{declared in global scope here}}1107} // namespace cwg1711108 1109namespace cwg172 { // cwg172: 2.71110  enum { zero };1111  static_assert(-1 < zero, "");1112 1113  enum { x = -1, y = (unsigned int)-1 };1114  static_assert(sizeof(x) > sizeof(int), "");1115 1116  enum { a = (unsigned int)-1 / 2 };1117  static_assert(sizeof(a) == sizeof(int), "");1118  static_assert(-a < 0, "");1119 1120  enum { b = (unsigned int)-1 / 2 + 1 };1121  static_assert(sizeof(b) == sizeof(unsigned int), "");1122  static_assert(-b > 0, "");1123 1124  enum { c = (unsigned long)-1 / 2 };1125  static_assert(sizeof(c) == sizeof(long), "");1126  static_assert(-c < 0, "");1127 1128  enum { d = (unsigned long)-1 / 2 + 1 };1129  static_assert(sizeof(d) == sizeof(unsigned long), "");1130  static_assert(-d > 0, "");1131 1132  enum { e = (unsigned long long)-1 / 2 };1133  // cxx98-error@-1 {{'long long' is a C++11 extension}}1134  static_assert(sizeof(e) == sizeof(long), "");1135  static_assert(-e < 0, "");1136 1137  enum { f = (unsigned long long)-1 / 2 + 1 };1138  // cxx98-error@-1 {{'long long' is a C++11 extension}}1139  static_assert(sizeof(f) == sizeof(unsigned long), "");1140  static_assert(-f > 0, "");1141} // namespace cwg1721142 1143namespace cwg173 { // cwg173: 2.71144  static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&1145                '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&1146                '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', "");1147} // namespace cwg1731148 1149// cwg174: sup 10121150 1151namespace cwg175 { // cwg175: 2.81152  struct A {}; // #cwg175-A1153  struct B : private A {}; // #cwg175-B1154  struct C : B {1155    A a;1156    // expected-error@-1 {{'A' is a private member of 'cwg175::A'}}1157    //   expected-note@#cwg175-B {{constrained by private inheritance here}}1158    //   expected-note@#cwg175-A {{member is declared here}}1159    cwg175::A b;1160  };1161} // namespace cwg1751162 1163namespace cwg176 { // cwg176: 3.11164  template<typename T> class Y;1165  template<> class Y<int> {1166    void f() {1167      typedef Y A; // #cwg176-A-first1168      typedef Y<char> A;1169      // expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}}1170      //   expected-note@#cwg176-A-first {{previous definition is here}}1171    }1172  };1173 1174  template<typename T> struct Base {}; // #cwg176-Base1175  template<typename T> struct Derived : public Base<T> {1176    void f() {1177      typedef typename Derived::template Base<T> A;1178      typedef typename Derived::Base A;1179    }1180  };1181  template struct Derived<int>;1182 1183  template<typename T> struct Derived2 : Base<int>, Base<char> {1184    typename Derived2::Base b;1185    // expected-error@-1 {{member 'Base' found in multiple base classes of different types}}1186    //   expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}}1187    //   expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}}1188    typename Derived2::Base<double> d;1189  };1190 1191  template<typename T> class X { // #cwg176-X1192    X *p1;1193    X<T> *p2;1194    X<int> *p3;1195    cwg176::X *p4; // #cwg176-p41196    // cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}}1197    //  cxx98-14-note@#cwg176-X {{template is declared here}}1198    // since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}}1199    //  since-cxx17-note@#cwg176-X {{template is declared here}}1200  };1201} // namespace cwg1761202 1203namespace cwg177 { // cwg177: 2.71204  struct B {};1205  struct A {1206    A(A &); // #cwg177-A-copy-ctor1207    A(const B &); // #cwg177-A-ctor-from-B1208  };1209  B b;1210  A a = b;1211  // cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}}1212  //   cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}1213  //   cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}}1214 1215  struct C { C(C&); }; // #cwg177-C-copy-ctor1216  struct D : C {};1217  struct E { operator D(); };1218  E e;1219  C c = e;1220  // expected-error@-1 {{no viable constructor copying variable of type 'D'}}1221  //   expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}1222} // namespace cwg1771223 1224namespace cwg178 { // cwg178: 3.11225  static_assert(int() == 0, "");1226#if __cplusplus >= 201103L1227  static_assert(int{} == 0, "");1228  struct S { int a, b; };1229  static_assert(S{1}.b == 0, "");1230  struct T { constexpr T() : n() {} int n; };1231  static_assert(T().n == 0, "");1232  struct U : S { constexpr U() : S() {} };1233  static_assert(U().b == 0, "");1234#endif1235} // namespace cwg1781236 1237namespace cwg179 { // cwg179: 2.71238  void f();1239  int n = &f - &f;1240  // expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}}1241} // namespace cwg1791242 1243namespace cwg180 { // cwg180: 2.81244  template<typename T> struct X : T, T::some_base {1245    X() : T::some_type_that_might_be_T(), T::some_base() {}1246    friend class T::some_class;1247    void f() {1248      enum T::some_enum e;1249    }1250  };1251} // namespace cwg1801252 1253namespace cwg181 { // cwg181: 2.71254  namespace X {1255    template <template X<class T> > struct A { };1256    // expected-error@-1 +{{}}1257    template <template X<class T> > void f(A<X>) { }1258    // expected-error@-1 +{{}}1259  }1260 1261  namespace Y {1262    template <template <class T> class X> struct A { };1263    template <template <class T> class X> void f(A<X>) { }1264  }1265} // namespace cwg1811266 1267namespace cwg182 { // cwg182: 141268  template <class T> struct C {1269    void f();1270    void g();1271  };1272 1273  template <class T> void C<T>::f() {}1274  template <class T> void C<T>::g() {}1275 1276  class A {1277    class B {};1278    void f();1279  };1280 1281  template void C<A::B>::f();1282  template <> void C<A::B>::g();1283 1284  void A::f() {1285    C<B> cb;1286    cb.f();1287  }1288} // namespace cwg1821289 1290namespace cwg183 { // cwg183: sup 3821291  template<typename T> struct A {};1292  template<typename T> struct B {1293    typedef int X;1294  };1295  template<> struct A<int> {1296    typename B<int>::X x;1297    // cxx98-error@-1 {{'typename' outside of a template is a C++11 extension}}1298  };1299} // namespace cwg1831300 1301namespace cwg184 { // cwg184: 2.71302  template<typename T = float> struct B {};1303 1304  template<template<typename TT = float> class T> struct A {1305    void f();1306    void g();1307  };1308 1309  template<template<typename TT> class T> void A<T>::f() { // #cwg184-T1310    T<> t;1311    // expected-error@-1 {{too few template arguments for template template parameter 'T'}}1312    //   expected-note@#cwg184-T {{template is declared here}}1313  }1314 1315  template<template<typename TT = char> class T> void A<T>::g() {1316    T<> t;1317    typedef T<> X;1318    typedef T<char> X;1319  }1320 1321  void h() { A<B>().g(); }1322} // namespace cwg1841323 1324// cwg185 is in cwg185.cpp1325 1326namespace cwg187 { // cwg187: sup 4811327  const int Z = 1;1328  template<int X = Z, int Z = X> struct A;1329  typedef A<> T;1330  typedef A<1, 1> T;1331} // namespace cwg1871332 1333namespace cwg188 { // cwg188: 2.71334  char c[10];1335  static_assert(sizeof(0, c) == 10, "");1336} // namespace cwg1881337 1338namespace cwg190 { // cwg190: 191339struct A {1340  int a;1341  static double x;1342  int b;1343  void y();1344  int c;1345};1346 1347struct B {1348  int a;1349  void y();1350  int b;1351  static double x;1352  int c;1353};1354 1355static_assert(__is_layout_compatible(A, B), "");1356} // namespace cwg1901357 1358int cwg191_j;1359namespace cwg191 { // cwg191: 2.71360  namespace example1 {1361    struct outer {1362      static int i;1363      struct inner {1364        void f() {1365          struct local {1366            void g() {1367              i = 5;1368            }1369          };1370        }1371      };1372    };1373  }1374 1375  namespace example2 {1376    struct S {1377      void f() {1378        struct local2 {1379          void g() {1380            cwg191_j = 5;1381          }1382        };1383      }1384    };1385  }1386} // namespace cwg1911387 1388namespace cwg192 { // cwg192: 2.71389struct S {1390  void f(I i) { }1391  // expected-error@-1 {{unknown type name 'I'}}1392  typedef int I;1393};1394} // namespace cwg1921395 1396// cwg193 is in cwg193.cpp1397 1398namespace cwg194 { // cwg194: 2.71399  struct A {1400    A();1401    void A();1402    // expected-error@-1 {{constructor cannot have a return type}}1403  };1404  struct B {1405    void B();1406    // expected-error@-1 {{constructor cannot have a return type}}1407    B();1408  };1409  struct C {1410    inline explicit C(int) {}1411  };1412} // namespace cwg1941413 1414namespace cwg195 { // cwg195: 2.71415  void f();1416  int *p = (int*)&f;1417  // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}1418  void (*q)() = (void(*)())&p;1419  // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}1420} // namespace cwg1951421 1422namespace cwg197 { // cwg197: 2.71423  char &f(char);1424 1425  template <class T> void g(T t) {1426    char &a = f(1);1427    char &b = f(T(1));1428    // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}1429    //   expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}}1430    char &c = f(t);1431    // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}1432  }1433 1434  void f(int);1435 1436  enum E { e };1437  int &f(E);1438 1439  void h() {1440    g('a');1441    g(2);1442    g(e); // #cwg197-g-e-call1443  }1444} // namespace cwg1971445 1446namespace cwg198 { // cwg198: 2.91447  struct A {1448    int n;1449    struct B {1450      int m[sizeof(n)];1451      // cxx98-error@-1 {{invalid use of non-static data member 'n'}}1452      int f() { return n; }1453      // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}1454    };1455    struct C;1456    struct D;1457  };1458  struct A::C {1459    int m[sizeof(n)];1460    // cxx98-error@-1 {{invalid use of non-static data member 'n'}}1461    int f() { return n; }1462    // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}1463  };1464  struct A::D : A {1465    int m[sizeof(n)];1466    // cxx98-error@-1 {{invalid use of non-static data member 'n'}}1467    int f() { return n; }1468  };1469} // namespace cwg1981470 1471// cwg199 is in cwg199.cpp1472