154 lines · cpp
1// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=cxx23,new %s2// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fms-compatibility -verify=cxx23,old %s3// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20,old %s4 5// FIXME: This is a test for a temporary workaround where we disable simpler implicit moves6// in the STL when compiling with -fms-compatibility, because of issues with the7// implementation there.8// Feel free to delete this file when the workaround is not needed anymore.9 10#if __INCLUDE_LEVEL__ == 011 12#if __cpluscplus > 202002L && __cpp_implicit_move < 202207L13#error "__cpp_implicit_move not defined correctly"14#endif15 16struct nocopy {17 nocopy(nocopy &&);18};19 20int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}21int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}22nocopy mt3(nocopy x) { return x; }23 24namespace {25int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}26int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}27nocopy mt3(nocopy x) { return x; }28} // namespace29 30namespace foo {31int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}32int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}33namespace std {34int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}35int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}36nocopy mt3(nocopy x) { return x; }37} // namespace std38} // namespace foo39 40namespace std {41 42int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}43int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}44nocopy mt3(nocopy x) { return x; }45 46namespace {47int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}48int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}49nocopy mt3(nocopy x) { return x; }50} // namespace51 52namespace foo {53int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}54int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}55nocopy mt3(nocopy x) { return x; }56} // namespace foo57 58} // namespace std59 60#include __FILE__61 62#define SYSTEM63#include __FILE__64 65#elif !defined(SYSTEM)66 67int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}68int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}69nocopy ut3(nocopy x) { return x; }70 71namespace {72int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}73int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}74nocopy ut3(nocopy x) { return x; }75} // namespace76 77namespace foo {78int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}79int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}80nocopy ut3(nocopy x) { return x; }81namespace std {82int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}83int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}84nocopy ut3(nocopy x) { return x; }85} // namespace std86} // namespace foo87 88namespace std {89 90int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}91int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}92nocopy ut3(nocopy x) { return x; }93 94namespace {95int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}96int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}97nocopy ut3(nocopy x) { return x; }98} // namespace99 100namespace foo {101int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}102int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}103nocopy ut3(nocopy x) { return x; }104} // namespace foo105 106} // namespace std107 108#else109 110#pragma GCC system_header111 112int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}113int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}114nocopy st3(nocopy x) { return x; }115 116namespace {117int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}118int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}119nocopy st3(nocopy x) { return x; }120} // namespace121 122namespace foo {123int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}124int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}125nocopy st3(nocopy x) { return x; }126namespace std {127int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}128int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}129nocopy st3(nocopy x) { return x; }130} // namespace std131} // namespace foo132 133namespace std {134 135int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}136int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}137nocopy st3(nocopy x) { return x; }138 139namespace {140int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}141int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}142nocopy st3(nocopy x) { return x; }143} // namespace144 145namespace foo {146int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}147int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}148nocopy st3(nocopy x) { return x; }149} // namespace foo150 151} // namespace std152 153#endif154