[llvm] r306001 - [Testing/Support] Remove the const_cast in TakeExpected
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 06:11:50 PDT 2017
Author: labath
Date: Thu Jun 22 08:11:50 2017
New Revision: 306001
URL: http://llvm.org/viewvc/llvm-project?rev=306001&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Testing/Support/Error.h
Modified: llvm/trunk/include/llvm/Testing/Support/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Testing/Support/Error.h?rev=306001&r1=306000&r2=306001&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Testing/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Testing/Support/Error.h Thu Jun 22 08:11:50 2017
@@ -30,8 +30,8 @@ template <typename T> ExpectedHolder<T>
return Result;
}
-template <typename T> ExpectedHolder<T> TakeExpected(const Expected<T> &Exp) {
- return TakeExpected(const_cast<Expected<T> &>(Exp));
+template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &&Exp) {
+ return TakeExpected(Exp);
}
} // namespace detail
More information about the llvm-commits
mailing list