[llvm] r194032 - Fix MSVC build by not putting an error_code directly in a union.
Rafael EspĂndola
rafael.espindola at gmail.com
Mon Nov 4 17:20:07 PST 2013
and my MSVC I mean c++03. Sorry for the breakage.
On 4 November 2013 17:07, Rafael Espindola <rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Mon Nov 4 19:07:06 2013
> New Revision: 194032
>
> URL: http://llvm.org/viewvc/llvm-project?rev=194032&view=rev
> Log:
> Fix MSVC build by not putting an error_code directly in a union.
>
> Modified:
> llvm/trunk/include/llvm/Support/ErrorOr.h
>
> Modified: llvm/trunk/include/llvm/Support/ErrorOr.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorOr.h?rev=194032&r1=194031&r2=194032&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/ErrorOr.h (original)
> +++ llvm/trunk/include/llvm/Support/ErrorOr.h Mon Nov 4 19:07:06 2013
> @@ -115,11 +115,11 @@ public:
> is_error_condition_enum<E>::value,
> void *>::type = 0)
> : HasError(true), IsValid(true) {
> - Error = make_error_code(ErrorCode);
> + new (getError()) error_code(make_error_code(ErrorCode));
> }
>
> ErrorOr(llvm::error_code EC) : HasError(true), IsValid(true) {
> - Error = EC;
> + new (getError()) error_code(EC);
> }
>
> ErrorOr(T Val) : HasError(false), IsValid(true) {
> @@ -186,7 +186,7 @@ public:
>
> operator llvm::error_code() const {
> assert(IsValid && "Can't do anything on a default constructed ErrorOr!");
> - return HasError ? Error : llvm::error_code::success();
> + return HasError ? *getError() : llvm::error_code::success();
> }
>
> pointer operator ->() {
> @@ -210,8 +210,8 @@ private:
> new (get()) storage_type(*Other.get());
> } else {
> // Get other's error.
> - Error = Other.Error;
> HasError = true;
> + new (getError()) error_code(Other);
> }
> }
>
> @@ -249,8 +249,8 @@ private:
> Other.IsValid = false;
> } else {
> // Get other's error.
> - Error = Other.Error;
> HasError = true;
> + new (getError()) error_code(Other);
> // Tell other not to do any destruction.
> Other.IsValid = false;
> }
> @@ -286,9 +286,20 @@ private:
> return reinterpret_cast<const storage_type*>(TStorage.buffer);
> }
>
> + error_code *getError() {
> + assert(IsValid && "Can't do anything on a default constructed ErrorOr!");
> + assert(HasError && "Cannot get error when a value exists!");
> + return reinterpret_cast<error_code*>(ErrorStorage.buffer);
> + }
> +
> + const error_code *getError() const {
> + return const_cast<ErrorOr<T> *>(this)->getError();
> + }
> +
> +
> union {
> AlignedCharArrayUnion<storage_type> TStorage;
> - error_code Error;
> + AlignedCharArrayUnion<error_code> ErrorStorage;
> };
> bool HasError : 1;
> bool IsValid : 1;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list