1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

FileManager: Use llvm::Expected in new getFileRef API

`FileManager::getFileRef` is a modern API which we expect to convert to
over time.  We should modernize the error handling as well, using
`llvm::Expected` instead of `llvm::ErrorOr`, to help clients that care
about errors to ensure nothing is missed.

However, not all clients care.  I've also added another path for those
that don't:

- `FileEntryRef` is now copy- and move-assignable (using a pointer
  instead of a reference).
- `FileManager::getOptionalFileRef` returns an `llvm::Optional` instead
  of `llvm::Expected`.
- Added an `llvm::expectedToOptional` utility in case this is useful
  elsewhere.

https://reviews.llvm.org/D66705

llvm-svn: 369943
This commit is contained in:
Duncan P. N. Exon Smith 2019-08-26 18:29:51 +00:00
parent 08c0a7aaec
commit d2ffaaeb6c

View File

@ -982,6 +982,20 @@ inline void consumeError(Error Err) {
handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {}); handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
} }
/// Convert an Expected to an Optional without doing anything. This method
/// should be used only where an error can be considered a reasonable and
/// expected return value.
///
/// Uses of this method are potentially indicative of problems: perhaps the
/// error should be propagated further, or the error-producer should just
/// return an Optional in the first place.
template <typename T> Optional<T> expectedToOptional(Expected<T> &&E) {
if (E)
return std::move(*E);
consumeError(E.takeError());
return None;
}
/// Helper for converting an Error to a bool. /// Helper for converting an Error to a bool.
/// ///
/// This method returns true if Err is in an error state, or false if it is /// This method returns true if Err is in an error state, or false if it is