From cf20b143c06263a30de76e3385e253bfd9cde020 Mon Sep 17 00:00:00 2001 From: faluco Date: Mon, 13 Sep 2021 15:06:57 +0200 Subject: [PATCH] Fix the default constructor of the optional class to avoid a spurious uninitialized value warning in older GCC versions (seen for ARM32 and GCC 8.3). Use a union of a byte and the real storage, and init the char by default. --- lib/include/srsran/adt/optional.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/include/srsran/adt/optional.h b/lib/include/srsran/adt/optional.h index 8a08df6f2..939665248 100644 --- a/lib/include/srsran/adt/optional.h +++ b/lib/include/srsran/adt/optional.h @@ -24,7 +24,7 @@ class optional public: using value_type = T; - optional() : has_val_(false) {} + optional() : has_val_(false), empty() {} optional(const T& t) : has_val_(true) { storage.emplace(t); } optional(T&& t) : has_val_(true) { storage.emplace(std::move(t)); } optional(const optional& other) : has_val_(other.has_value()) @@ -98,8 +98,11 @@ public: } private: - bool has_val_; - detail::type_storage storage; + bool has_val_; + union { + char empty; + detail::type_storage storage; + }; }; template