public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "sss@li-snyder.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header Date: Fri, 03 Dec 2021 23:46:31 +0000 [thread overview] Message-ID: <bug-103549-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103549 Bug ID: 103549 Summary: [12 regression] Uninitialized member warning from regex header Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: sss@li-snyder.org Target Milestone: --- hi - With a recent checkout of gcc12 (20211201) on a x86_64-pc-linux-gnu host, compiling the following source with -O2 -Wall gives a warning about an uninitialized member in the regex header: -- x.cc --------------------------------------------------- #include <string> #include <regex> std::string plover(char *s) { return std::regex_replace (s, std::regex{"xyzzy"}, "plugh"); } ----------------------------------------------------------- $ g++ -c -O2 -Wall x.cc In file included from /usr/local/gcc/include/c++/12.0.0/regex:66, from x.cc:2: In member function ‘std::__cxx11::match_results< <template-parameter-1-1>, <template-parameter-1-2> >& std::__cxx11::match_results< <template-parameter-1-1>, <template-parameter-1-2> >::operator=(const std::__cxx11::match_results< <template-parameter-1-1>, <template-parameter-1-2> >&) [with _Bi_iter = const char*; _Alloc = std::allocator<std::__cxx11::sub_match<const char*> >]’, inlined from ‘std::__cxx11::regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>& std::__cxx11::regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::operator=(const std::__cxx11::regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>&) [with _Bi_iter = const char*; _Ch_type = char; _Rx_traits = std::__cxx11::regex_traits<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/regex.h:2699:7, inlined from ‘std::__cxx11::regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::regex_iterator(_Bi_iter, _Bi_iter, const std::__cxx11::regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::regex_type&, std::regex_constants::match_flag_type) [with _Bi_iter = const char*; _Ch_type = char; _Rx_traits = std::__cxx11::regex_traits<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/regex.h:2685:10, inlined from ‘_Out_iter std::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const _Ch_type*, std::regex_constants::match_flag_type) [with _Out_iter = std::back_insert_iterator<std::__cxx11::basic_string<char> >; _Bi_iter = const char*; _Rx_traits = std::__cxx11::regex_traits<char>; _Ch_type = char]’ at /usr/local/gcc/include/c++/12.0.0/bits/regex.tcc:470:14, inlined from ‘std::__cxx11::basic_string<_Ch_type> std::regex_replace(const _Ch_type*, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const _Ch_type*, std::regex_constants::match_flag_type) [with _Rx_traits = std::__cxx11::regex_traits<char>; _Ch_type = char]’ at /usr/local/gcc/include/c++/12.0.0/bits/regex.h:2638:20, inlined from ‘std::string plover(char*)’ at x.cc:6:61: /usr/local/gcc/include/c++/12.0.0/bits/regex.h:1784:7: warning: ‘<unnamed>.std::__cxx11::regex_iterator<const char*, char, std::__cxx11::regex_traits<char> >::_M_match.std::__cxx11::match_results<const char*>::_M_begin’ may be used uninitialized [-Wmaybe-uninitialized] 1784 | operator=(const match_results&) = default; | ^~~~~~~~ /usr/local/gcc/include/c++/12.0.0/bits/regex.h: In function ‘std::string plover(char*)’: /usr/local/gcc/include/c++/12.0.0/bits/regex.h:2685:19: note: ‘<anonymous>’ declared here 2685 | *this = regex_iterator(); | ^~~~~~~~~~~~~~~~ $ This warning seems to be correct. The match_results class in regex.h is default-constructed here, and it has a member _Bi_iter _M_begin; In this example, _Bi_iter is const char*, so it is indeed not initialized if the class is default-constructed. The following change gets rid of the warning for me: diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 785edc71800..5318f378ada 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -2109,7 +2109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _M_suffix() { return _Unchecked::operator[](_Unchecked::size() - 1); } - _Bi_iter _M_begin; + _Bi_iter _M_begin {}; /// @endcond };
next reply other threads:[~2021-12-03 23:46 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-03 23:46 sss@li-snyder.org [this message] 2021-12-04 1:00 ` [Bug libstdc++/103549] " redi at gcc dot gnu.org 2021-12-04 15:55 ` cvs-commit at gcc dot gnu.org 2021-12-06 8:21 ` rguenth at gcc dot gnu.org 2021-12-06 10:39 ` [Bug libstdc++/103549] " redi at gcc dot gnu.org 2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org 2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org 2022-01-05 22:08 ` redi at gcc dot gnu.org 2022-05-09 16:39 ` cvs-commit at gcc dot gnu.org 2022-05-09 19:44 ` redi at gcc dot gnu.org
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=bug-103549-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).