From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 9FECC3839427; Thu, 22 Jul 2021 13:34:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FECC3839427 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-2468] libstdc++: Initialize all subobjects of std::function X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 254e5d19a177af23a77b67fd51d0d1a25eaabfc7 X-Git-Newrev: c22bcfd2f7dc9bb5ad394720f4a612327dc898ba Message-Id: <20210722133455.9FECC3839427@sourceware.org> Date: Thu, 22 Jul 2021 13:34:55 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2021 13:34:55 -0000 https://gcc.gnu.org/g:c22bcfd2f7dc9bb5ad394720f4a612327dc898ba commit r12-2468-gc22bcfd2f7dc9bb5ad394720f4a612327dc898ba Author: Jonathan Wakely Date: Thu Jul 22 11:57:38 2021 +0100 libstdc++: Initialize all subobjects of std::function The std::function::swap member swaps each data member unconditionally, resulting in -Wmaybe-uninitialized warnings for a default constructed object. This happens because the _M_invoker and _M_functor members are only initialized if the function has a target. This change ensures that all subobjects are zero-initialized on construction. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/std_function.h (_Function_base): Add default member initializers and define constructor as defaulted. (function::_M_invoker): Add default member initializer. Diff: --- libstdc++-v3/include/bits/std_function.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 31eba2b822c..c08484465c9 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -237,7 +237,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __functor._M_access<_Functor*>() = new _Functor(std::move(__f)); } }; - _Function_base() : _M_manager(nullptr) { } + _Function_base() = default; ~_Function_base() { @@ -247,11 +247,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_empty() const { return !_M_manager; } - typedef bool (*_Manager_type)(_Any_data&, const _Any_data&, - _Manager_operation); + using _Manager_type + = bool (*)(_Any_data&, const _Any_data&, _Manager_operation); - _Any_data _M_functor; - _Manager_type _M_manager; + _Any_data _M_functor{}; + _Manager_type _M_manager{}; }; template @@ -261,7 +261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class _Function_handler<_Res(_ArgTypes...), _Functor> : public _Function_base::_Base_manager<_Functor> { - typedef _Function_base::_Base_manager<_Functor> _Base; + using _Base = _Function_base::_Base_manager<_Functor>; public: static bool @@ -414,7 +414,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION function(_Functor __f) : _Function_base() { - typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler; + using _My_handler = _Function_handler<_Res(_ArgTypes...), _Functor>; if (_My_handler::_M_not_empty_function(__f)) { @@ -634,8 +634,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: using _Invoker_type = _Res (*)(const _Any_data&, _ArgTypes&&...); - _Invoker_type _M_invoker; - }; + _Invoker_type _M_invoker = nullptr; + }; #if __cpp_deduction_guides >= 201606 template