From 0363236dc754180a0215a818d58587943f84fb53 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 8 Sep 2017 19:28:09 +0800 Subject: [PATCH] encoding: reset optional<> if it is uninitialized * should reset it, in case we reuse it after initializing it. * initialize the value of `p` using the C++11 style initializer, so it is zero-initialized. * revert 2a83ef3c which disables a warning of: ./include/encoding.h:317:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized] where the `t` is the temporary variable for initializing the value of `p`. Signed-off-by: Kefu Chai --- src/include/encoding.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/encoding.h b/src/include/encoding.h index f7ee5d118285c..5015e19024b2d 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -297,16 +297,16 @@ inline void encode(const boost::optional &p, bufferlist &bl) #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wuninitialized" -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" template inline void decode(boost::optional &p, bufferlist::iterator &bp) { __u8 present; ::decode(present, bp); if (present) { - T t; - p = t; + p = T{}; decode(p.get(), bp); + } else { + p = boost::none; } } #pragma GCC diagnostic pop -- 2.39.5