public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-9285] libstdc++: Initialize all subobjects of std::function Date: Wed, 24 Nov 2021 11:50:57 +0000 (GMT) [thread overview] Message-ID: <20211124115057.9EE823857C65@sourceware.org> (raw) https://gcc.gnu.org/g:e1e44deddfa2424e45507a7a4c19c99638c6b08d commit r11-9285-ge1e44deddfa2424e45507a7a4c19c99638c6b08d Author: Jonathan Wakely <jwakely@redhat.com> 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 <jwakely@redhat.com> 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. (cherry picked from commit c22bcfd2f7dc9bb5ad394720f4a612327dc898ba) 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 da15bd20e37..fb86ff1c5f8 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<typename _Signature, typename _Functor> @@ -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 @@ -422,7 +422,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)) { @@ -642,8 +642,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<typename>
reply other threads:[~2021-11-24 11:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211124115057.9EE823857C65@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).