16 #ifndef LLVM_SUPPORT_ERROROR_H
17 #define LLVM_SUPPORT_ERROROR_H
21 #include <system_error>
22 #include <type_traits>
35 operator T &()
const {
return *Storage; }
36 T &
get()
const {
return *Storage; }
70 template <
class OtherT>
friend class ErrorOr;
72 static const bool isRef = std::is_reference<T>::value;
77 using storage_type =
typename std::conditional<isRef, wrap, T>::type;
80 using reference =
typename std::remove_reference<T>::type &;
81 using const_reference =
const typename std::remove_reference<T>::type &;
82 using pointer =
typename std::remove_reference<T>::type *;
83 using const_pointer =
const typename std::remove_reference<T>::type *;
88 typename std::enable_if<std::is_error_code_enum<E>::value ||
89 std::is_error_condition_enum<E>::value,
90 void *>::type =
nullptr)
96 new (getErrorStorage()) std::error_code(EC);
99 template <
class OtherT>
101 typename std::enable_if<std::is_convertible<OtherT, T>::value>::type
104 new (getStorage())
storage_type(std::forward<OtherT>(Val));
108 copyConstruct(Other);
111 template <
class OtherT>
114 typename std::enable_if<std::is_convertible<OtherT, T>::value>::type * =
116 copyConstruct(Other);
119 template <
class OtherT>
122 typename std::enable_if<
123 !std::is_convertible<OtherT, const T &>::value>::type * =
nullptr) {
124 copyConstruct(Other);
128 moveConstruct(std::move(
Other));
131 template <
class OtherT>
134 typename std::enable_if<std::is_convertible<OtherT, T>::value>::type * =
136 moveConstruct(std::move(
Other));
141 template <
class OtherT>
144 typename std::enable_if<!std::is_convertible<OtherT, T>::value>::type * =
146 moveConstruct(std::move(
Other));
155 moveAssign(std::move(
Other));
161 getStorage()->~storage_type();
165 explicit operator bool()
const {
169 reference
get() {
return *getStorage(); }
170 const_reference
get()
const {
return const_cast<ErrorOr<T> *
>(
this)->
get(); }
173 return HasError ? *getErrorStorage() : std::error_code();
177 return toPointer(getStorage());
180 const_pointer
operator->()
const {
return toPointer(getStorage()); }
183 return *getStorage();
186 const_reference
operator*()
const {
return *getStorage(); }
189 template <
class OtherT>
191 if (!Other.HasError) {
198 new (getErrorStorage()) std::error_code(Other.
getError());
203 static bool compareThisIfSameType(
const T1 &a,
const T1 &b) {
207 template <
class T1,
class T2>
208 static bool compareThisIfSameType(
const T1 &a,
const T2 &b) {
212 template <
class OtherT>
213 void copyAssign(
const ErrorOr<OtherT> &Other) {
214 if (compareThisIfSameType(*
this, Other))
221 template <
class OtherT>
222 void moveConstruct(ErrorOr<OtherT> &&Other) {
223 if (!Other.HasError) {
226 new (getStorage())
storage_type(std::move(*Other.getStorage()));
230 new (getErrorStorage()) std::error_code(Other.getError());
234 template <
class OtherT>
235 void moveAssign(ErrorOr<OtherT> &&Other) {
236 if (compareThisIfSameType(*
this, Other))
240 new (
this)
ErrorOr(std::move(Other));
243 pointer toPointer(pointer Val) {
247 const_pointer toPointer(const_pointer Val)
const {
return Val; }
249 pointer toPointer(
wrap *Val) {
253 const_pointer toPointer(
const wrap *Val)
const {
return &Val->get(); }
256 assert(!HasError &&
"Cannot get value when an error exists!");
261 assert(!HasError &&
"Cannot get value when an error exists!");
265 std::error_code *getErrorStorage() {
266 assert(HasError &&
"Cannot get error when a value exists!");
270 const std::error_code *getErrorStorage()
const {
271 return const_cast<ErrorOr<T> *
>(
this)->getErrorStorage();
281 template <
class T,
class E>
282 typename std::enable_if<std::is_error_code_enum<E>::value ||
283 std::is_error_condition_enum<E>::value,
286 return Err.getError() == Code;
291 #endif // LLVM_SUPPORT_ERROROR_H
ErrorOr(const ErrorOr< OtherT > &Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
std::error_code getError() const
Represents either an error or a value T.
ErrorOr & operator=(const ErrorOr &Other)
ErrorOr(OtherT &&Val, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
typename std::conditional< isRef, wrap, T >::type storage_type
const_pointer operator->() const
std::error_code make_error_code(BitcodeError E)
ErrorOr(E ErrorCode, typename std::enable_if< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void * >::type=nullptr)
Function Alias Analysis false
AlignedCharArrayUnion< std::error_code > ErrorStorage
ErrorOr(const ErrorOr &Other)
AlignedCharArrayUnion< storage_type > TStorage
ErrorOr(ErrorOr< OtherT > &&Other, typename std::enable_if<!std::is_convertible< OtherT, T >::value >::type *=nullptr)
ErrorOr(std::error_code EC)
ErrorOr(ErrorOr< OtherT > &&Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
LLVMAttributeRef wrap(Attribute Attr)
ErrorOr(const ErrorOr< OtherT > &Other, typename std::enable_if< !std::is_convertible< OtherT, const T & >::value >::type *=nullptr)
Stores a reference that can be changed.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ErrorOr & operator=(ErrorOr &&Other)
const_reference operator*() const
bool operator==(uint64_t V1, const APInt &V2)