diff options
Diffstat (limited to 'include/llvm/Support/ErrorOr.h')
-rw-r--r-- | include/llvm/Support/ErrorOr.h | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/include/llvm/Support/ErrorOr.h b/include/llvm/Support/ErrorOr.h index ca6ede73e8df1..877f4063cd232 100644 --- a/include/llvm/Support/ErrorOr.h +++ b/include/llvm/Support/ErrorOr.h @@ -23,20 +23,6 @@ #include <type_traits> namespace llvm { -template<class T, class V> -typename std::enable_if< std::is_constructible<T, V>::value - , typename std::remove_reference<V>::type>::type && - moveIfMoveConstructible(V &Val) { - return std::move(Val); -} - -template<class T, class V> -typename std::enable_if< !std::is_constructible<T, V>::value - , typename std::remove_reference<V>::type>::type & -moveIfMoveConstructible(V &Val) { - return Val; -} - /// \brief Stores a reference that can be changed. template <typename T> class ReferenceStorage { @@ -72,7 +58,7 @@ public: /// unary * and -> operators provide pointer like access to the value. Accessing /// the value when there is an error has undefined behavior. /// -/// When T is a reference type the behaivor is slightly different. The reference +/// When T is a reference type the behavior is slightly different. The reference /// is held in a std::reference_wrapper<std::remove_reference<T>::type>, and /// there is special handling to make operator -> work as if T was not a /// reference. @@ -98,7 +84,7 @@ public: ErrorOr(E ErrorCode, typename std::enable_if<std::is_error_code_enum<E>::value || std::is_error_condition_enum<E>::value, - void *>::type = 0) + void *>::type = nullptr) : HasError(true) { new (getErrorStorage()) std::error_code(make_error_code(ErrorCode)); } @@ -107,8 +93,12 @@ public: new (getErrorStorage()) std::error_code(EC); } - ErrorOr(T Val) : HasError(false) { - new (getStorage()) storage_type(moveIfMoveConstructible<storage_type>(Val)); + template <class OtherT> + ErrorOr(OtherT &&Val, + typename std::enable_if<std::is_convertible<OtherT, T>::value>::type + * = nullptr) + : HasError(false) { + new (getStorage()) storage_type(std::forward<OtherT>(Val)); } ErrorOr(const ErrorOr &Other) { @@ -278,7 +268,6 @@ private: return const_cast<ErrorOr<T> *>(this)->getErrorStorage(); } - union { AlignedCharArrayUnion<storage_type> TStorage; AlignedCharArrayUnion<std::error_code> ErrorStorage; @@ -295,4 +284,4 @@ operator==(const ErrorOr<T> &Err, E Code) { } } // end namespace llvm -#endif +#endif // LLVM_SUPPORT_ERROROR_H |