private:
void assertIsChecked() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
if (!getChecked() || getPtr()) {
dbgs() << "Program aborted due to an unhandled Error:\n";
if (getPtr())
}
void setPtr(ErrorInfoBase *EI) {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
Payload = reinterpret_cast<ErrorInfoBase*>(
(reinterpret_cast<uintptr_t>(EI) &
~static_cast<uintptr_t>(0x1)) |
}
bool getChecked() const {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
return (reinterpret_cast<uintptr_t>(Payload) & 0x1) == 0;
#else
return true;
public:
/// Create an Expected<T> error value from the given Error.
Expected(Error Err)
- : HasError(true),
-#ifndef NDEBUG
+ : HasError(true)
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
// Expected is unchecked upon construction in Debug builds.
- Unchecked(true)
-#else
- // Expected's unchecked flag is set to false in Release builds. This
- // allows Expected values constructed in a Release build library to be
- // consumed by a Debug build application.
- Unchecked(false)
+ , Unchecked(true)
#endif
-
{
assert(Err && "Cannot create Expected<T> from Error success value.");
new (getErrorStorage()) error_type(Err.takePayload());
Expected(OtherT &&Val,
typename std::enable_if<std::is_convertible<OtherT, T>::value>::type
* = nullptr)
- : HasError(false),
-#ifndef NDEBUG
+ : HasError(false)
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
// Expected is unchecked upon construction in Debug builds.
- Unchecked(true)
-#else
- // Expected's 'unchecked' flag is set to false in Release builds. This
- // allows Expected values constructed in a Release build library to be
- // consumed by a Debug build application.
- Unchecked(false)
+ , Unchecked(true)
#endif
{
new (getStorage()) storage_type(std::forward<OtherT>(Val));
/// \brief Return false if there is an error.
explicit operator bool() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
Unchecked = HasError;
#endif
return !HasError;
/// only be safely destructed. No further calls (beside the destructor) should
/// be made on the Expected<T> vaule.
Error takeError() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
Unchecked = false;
#endif
return HasError ? Error(std::move(*getErrorStorage())) : Error::success();
template <class OtherT> void moveConstruct(Expected<OtherT> &&Other) {
HasError = Other.HasError;
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
Unchecked = true;
Other.Unchecked = false;
+#endif
if (!HasError)
new (getStorage()) storage_type(std::move(*Other.getStorage()));
}
void assertIsChecked() {
-#ifndef NDEBUG
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
if (Unchecked) {
dbgs() << "Expected<T> must be checked before access or destruction.\n";
if (HasError) {
AlignedCharArrayUnion<error_type> ErrorStorage;
};
bool HasError : 1;
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
bool Unchecked : 1;
+#endif
};
/// This class wraps a std::error_code in a Error.