15 #ifndef LLVM_SUPPORT_ERROROR_H 16 #define LLVM_SUPPORT_ERROROR_H 20 #include <system_error> 21 #include <type_traits> 57 template <
class OtherT>
friend class ErrorOr;
59 static const bool isRef = std::is_reference<T>::value;
61 using wrap = std::reference_wrapper<typename std::remove_reference<T>::type>;
64 using storage_type =
typename std::conditional<isRef, wrap, T>::type;
67 using reference =
typename std::remove_reference<T>::type &;
68 using const_reference =
const typename std::remove_reference<T>::type &;
69 using pointer =
typename std::remove_reference<T>::type *;
70 using const_pointer =
const typename std::remove_reference<T>::type *;
75 typename std::enable_if<std::is_error_code_enum<E>::value ||
76 std::is_error_condition_enum<E>::value,
77 void *>::
type =
nullptr)
83 new (getErrorStorage()) std::error_code(EC);
86 template <
class OtherT>
88 typename std::enable_if<std::is_convertible<OtherT, T>::value>::
type 91 new (getStorage())
storage_type(std::forward<OtherT>(Val));
98 template <
class OtherT>
101 typename std::enable_if<std::is_convertible<OtherT, T>::value>::
type * =
103 copyConstruct(Other);
106 template <
class OtherT>
109 typename std::enable_if<
110 !std::is_convertible<OtherT, const T &>::value>::
type * =
nullptr) {
111 copyConstruct(Other);
115 moveConstruct(std::move(
Other));
118 template <
class OtherT>
121 typename std::enable_if<std::is_convertible<OtherT, T>::value>::
type * =
123 moveConstruct(std::move(
Other));
128 template <
class OtherT>
131 typename std::enable_if<!std::is_convertible<OtherT, T>::value>::
type * =
133 moveConstruct(std::move(
Other));
142 moveAssign(std::move(
Other));
148 getStorage()->~storage_type();
152 explicit operator bool()
const {
156 reference
get() {
return *getStorage(); }
157 const_reference
get()
const {
return const_cast<ErrorOr<T> *
>(
this)->
get(); }
160 return HasError ? *getErrorStorage() : std::error_code();
164 return toPointer(getStorage());
167 const_pointer
operator->()
const {
return toPointer(getStorage()); }
170 return *getStorage();
173 const_reference
operator*()
const {
return *getStorage(); }
176 template <
class OtherT>
178 if (!Other.HasError) {
185 new (getErrorStorage()) std::error_code(Other.
getError());
190 static bool compareThisIfSameType(
const T1 &a,
const T1 &b) {
194 template <
class T1,
class T2>
195 static bool compareThisIfSameType(
const T1 &a,
const T2 &b) {
199 template <
class OtherT>
201 if (compareThisIfSameType(*
this, Other))
208 template <
class OtherT>
210 if (!Other.HasError) {
213 new (getStorage())
storage_type(std::move(*Other.getStorage()));
217 new (getErrorStorage()) std::error_code(Other.
getError());
221 template <
class OtherT>
223 if (compareThisIfSameType(*
this, Other))
227 new (
this)
ErrorOr(std::move(Other));
230 pointer toPointer(pointer Val) {
234 const_pointer toPointer(const_pointer Val)
const {
return Val; }
236 pointer toPointer(wrap *Val) {
240 const_pointer toPointer(
const wrap *Val)
const {
return &Val->get(); }
243 assert(!HasError &&
"Cannot get value when an error exists!");
248 assert(!HasError &&
"Cannot get value when an error exists!");
252 std::error_code *getErrorStorage() {
253 assert(HasError &&
"Cannot get error when a value exists!");
257 const std::error_code *getErrorStorage()
const {
258 return const_cast<ErrorOr<T> *
>(
this)->getErrorStorage();
268 template <
class T,
class E>
269 typename std::enable_if<std::is_error_code_enum<E>::value ||
270 std::is_error_condition_enum<E>::value,
278 #endif // LLVM_SUPPORT_ERROROR_H ErrorOr(const ErrorOr< OtherT > &Other, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
Represents either an error or a value T.
ErrorOr & operator=(const ErrorOr &Other)
This class represents lattice values for constants.
ErrorOr(OtherT &&Val, typename std::enable_if< std::is_convertible< OtherT, T >::value >::type *=nullptr)
char buffer[sizeof(llvm::detail::SizerImpl< T, Ts... >)]
typename std::conditional< isRef, wrap, T >::type storage_type
block Block Frequency true
ErrorOr(const ErrorOr< OtherT > &Other, typename std::enable_if< !std::is_convertible< OtherT, const T &>::value >::type *=nullptr)
std::error_code make_error_code(BitcodeError E)
const_pointer operator->() const
AlignedCharArrayUnion< std::error_code > ErrorStorage
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ErrorOr(const ErrorOr &Other)
std::error_code getError() const
AlignedCharArrayUnion< storage_type > TStorage
ErrorOr(E ErrorCode, typename std::enable_if< std::is_error_code_enum< E >::value||std::is_error_condition_enum< E >::value, void *>::type=nullptr)
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)
const_reference operator*() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ErrorOr & operator=(ErrorOr &&Other)
bool operator==(uint64_t V1, const APInt &V2)