[Bug c++/99536] unexplained warning on "uninitialized value" in std::normal_distribution

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 11 13:30:35 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99536

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC 5 is old and no longer supported.

This is probably a jump threading bug. The _M_saved member is only ever used if
_M_saved_available says it can be used, and that is only the case after it's
been initialized.

We could probably just initialize it on construction to avoid the false
positive warning:

--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -2024,12 +2024,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       explicit
       normal_distribution(result_type __mean,
                          result_type __stddev = result_type(1))
-      : _M_param(__mean, __stddev), _M_saved_available(false)
+      : _M_param(__mean, __stddev)
       { }

       explicit
       normal_distribution(const param_type& __p)
-      : _M_param(__p), _M_saved_available(false)
+      : _M_param(__p)
       { }

       /**
@@ -2166,8 +2166,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                        const param_type& __p);

       param_type  _M_param;
-      result_type _M_saved;
-      bool        _M_saved_available;
+      result_type _M_saved = 0;
+      bool        _M_saved_available = false;
     };

   /**


More information about the Gcc-bugs mailing list