From 6694e4a6b1522c2a8ed3e258e130d2a40f073113 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 22 Jun 2017 13:11:50 +0000 Subject: [PATCH] [Testing/Support] Remove the const_cast in TakeExpected Summary: The const_cast in the "const" version of TakeExpected was quite dangerous, as the function does indeed modify the apparently const argument. I assume the reason the const overload was added was to make the function bind to xvalues(temporaries). That can be also achieved with rvalue references, so I use that instead. Using the ASSERT macros on const Expected objects will now become illegal, but I believe that is correct, as it is not actually possible to inspect the error stored in an Expected object without modifying it. Reviewers: zturner, chandlerc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34405 llvm-svn: 306001 --- include/llvm/Testing/Support/Error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/llvm/Testing/Support/Error.h b/include/llvm/Testing/Support/Error.h index d5275290159..f23d289266a 100644 --- a/include/llvm/Testing/Support/Error.h +++ b/include/llvm/Testing/Support/Error.h @@ -30,8 +30,8 @@ template ExpectedHolder TakeExpected(Expected &Exp) { return Result; } -template ExpectedHolder TakeExpected(const Expected &Exp) { - return TakeExpected(const_cast &>(Exp)); +template ExpectedHolder TakeExpected(Expected &&Exp) { + return TakeExpected(Exp); } } // namespace detail