[clang] fix oops: enable implicit moves in MSVC compatibility mode
authorMatheus Izvekov <mizvekov@gmail.com>
Mon, 19 Jul 2021 19:35:18 +0000 (21:35 +0200)
committerMatheus Izvekov <mizvekov@gmail.com>
Tue, 20 Jul 2021 21:32:05 +0000 (23:32 +0200)
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

clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

index 643dde4..2ae27de 100644 (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;
index 2143c05..07db9b8 100644 (file)
@@ -48,3 +48,5 @@ void test5() try {
   throw x; // new-error {{no matching constructor for initialization}}
 } catch (...) {
 }
+
+MoveOnly test6(MoveOnly x) { return x; }