[clang] fix oops: enable implicit moves in MSVC compatibility mode

When disabling simpler implicit moves in MSVC compatibility mode as
a workaround in D105518, we forgot to make the opposite change and
enable regular (P1825) implicit moves in the same mode.

As a result, we were not doing any implicit moves at all. OOPS!

This fixes it and adds test for this.

This is a fix to a temporary workaround, there is ongoing
work to replace this, applying the workaround only to
system headers and the ::stl namespace.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D106303
This commit is contained in:
Matheus Izvekov 2021-07-19 21:35:18 +02:00
parent 808bbc2c47
commit 1d68ecafd6
2 changed files with 8 additions and 1 deletions

View File

@ -3483,7 +3483,12 @@ ExprResult
Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
const NamedReturnInfo &NRInfo,
Expr *Value) {
if (!getLangOpts().CPlusPlus2b && NRInfo.isMoveEligible()) {
// FIXME: We force P1825 implicit moves here in msvc compatibility mode
// because we are disabling simpler implicit moves as a temporary
// work around, as the MSVC STL has issues with this change.
// We will come back later with a more targeted approach.
if ((!getLangOpts().CPlusPlus2b || getLangOpts().MSVCCompat) &&
NRInfo.isMoveEligible()) {
ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
CK_NoOp, Value, VK_XValue, FPOptionsOverride());
Expr *InitExpr = &AsRvalue;

View File

@ -48,3 +48,5 @@ void test5() try {
throw x; // new-error {{no matching constructor for initialization}}
} catch (...) {
}
MoveOnly test6(MoveOnly x) { return x; }