Index: llvm/include/llvm/Support/Error.h =================================================================== --- llvm/include/llvm/Support/Error.h +++ llvm/include/llvm/Support/Error.h @@ -223,7 +223,7 @@ 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()) @@ -244,7 +244,7 @@ } void setPtr(ErrorInfoBase *EI) { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Payload = reinterpret_cast( (reinterpret_cast(EI) & ~static_cast(0x1)) | @@ -255,7 +255,7 @@ } bool getChecked() const { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS return (reinterpret_cast(Payload) & 0x1) == 0; #else return true; @@ -636,17 +636,11 @@ public: /// Create an Expected 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 from Error success value."); new (getErrorStorage()) error_type(Err.takePayload()); @@ -663,15 +657,10 @@ Expected(OtherT &&Val, typename std::enable_if::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(Val)); @@ -716,7 +705,7 @@ /// \brief Return false if there is an error. explicit operator bool() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Unchecked = HasError; #endif return !HasError; @@ -744,7 +733,7 @@ /// only be safely destructed. No further calls (beside the destructor) should /// be made on the Expected vaule. Error takeError() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS Unchecked = false; #endif return HasError ? Error(std::move(*getErrorStorage())) : Error::success(); @@ -787,8 +776,10 @@ template void moveConstruct(Expected &&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())); @@ -830,7 +821,7 @@ } void assertIsChecked() { -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS if (Unchecked) { dbgs() << "Expected must be checked before access or destruction.\n"; if (HasError) { @@ -850,7 +841,9 @@ AlignedCharArrayUnion ErrorStorage; }; bool HasError : 1; +#if LLVM_ENABLE_ABI_BREAKING_CHECKS bool Unchecked : 1; +#endif }; /// This class wraps a std::error_code in a Error.