diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h --- a/llvm/include/llvm/Support/Casting.h +++ b/llvm/include/llvm/Support/Casting.h @@ -355,7 +355,7 @@ static inline CastResultType doCastIfPossible(std::unique_ptr &&f) { if (!Self::isPossible(f.get())) return castFailed(); - return doCast(std::forward &&>(f)); + return doCast(std::forward>(f)); } }; diff --git a/llvm/unittests/Support/Casting.cpp b/llvm/unittests/Support/Casting.cpp --- a/llvm/unittests/Support/Casting.cpp +++ b/llvm/unittests/Support/Casting.cpp @@ -212,6 +212,14 @@ // EXPECT_EQ(F4, null_foo); foo *F5 = B1.daz(); EXPECT_NE(F5, null_foo); + + std::unique_ptr BP(B2); + auto FP = dyn_cast(std::move(BP)); + static_assert(std::is_same_v, decltype(FP)>, + "Incorrect deduced return type!"); + EXPECT_NE(FP.get(), null_foo); + EXPECT_EQ(BP.get(), nullptr); + FP.release(); } // All these tests forward to dyn_cast_if_present, so they also provde an