From 9606182f78192bc644d63f199435ab2296e3ae11 Mon Sep 17 00:00:00 2001 From: Sherman Ye Date: Thu, 23 Dec 2021 15:18:18 +0800 Subject: [PATCH] Try to fix "uninitialized" error --- .github/workflows/pull_request.yml | 1 - src/common/base/StatusOr.h | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 018bbcfb1f1..08bfd000fbc 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -125,7 +125,6 @@ jobs: esac - name: Make run: | - ccache -C ccache -z cmake --build build/ -j $(nproc) ccache -s diff --git a/src/common/base/StatusOr.h b/src/common/base/StatusOr.h index 05e1721e927..89e702be361 100644 --- a/src/common/base/StatusOr.h +++ b/src/common/base/StatusOr.h @@ -290,16 +290,19 @@ class StatusOr final { void resetValue() { destructValue(); + new (&variant_) Variant(); state_ = kVoid; } void resetStatus() { destructStatus(); + new (&variant_) Variant(); state_ = kVoid; } void destruct() { if (isVoid()) { + destructStatus(); return; } if (hasValue()) { @@ -311,13 +314,14 @@ class StatusOr final { void reset() { destruct(); + new (&variant_) Variant(); state_ = kVoid; } private: // Variant type to hold a `Status', or a `T', or nothing union Variant { - Variant() {} + Variant() : status_(Status()) {} Variant(const Status &status) : status_(status) {} Variant(Status &&status) : status_(std::move(status)) {} template >>