[PATCH] D34405: [Testing/Support] Remove the const_cast in TakeExpected
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 09:02:17 PDT 2017
labath created this revision.
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.
https://reviews.llvm.org/D34405
Files:
include/llvm/Testing/Support/Error.h
Index: include/llvm/Testing/Support/Error.h
===================================================================
--- include/llvm/Testing/Support/Error.h
+++ include/llvm/Testing/Support/Error.h
@@ -30,8 +30,8 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34405.103212.patch
Type: text/x-patch
Size: 503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170620/5e174661/attachment.bin>
More information about the llvm-commits
mailing list