Skip to content

Commit

Permalink
[clang] fix oops: enable implicit moves in MSVC compatibility mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mizvekov committed Jul 20, 2021
1 parent 808bbc2 commit 1d68eca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ void test5() try {
throw x; // new-error {{no matching constructor for initialization}}
} catch (...) {
}

MoveOnly test6(MoveOnly x) { return x; }

0 comments on commit 1d68eca

Please sign in to comment.