public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header
@ 2021-12-03 23:46 sss@li-snyder.org
  2021-12-04  1:00 ` [Bug libstdc++/103549] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: sss@li-snyder.org @ 2021-12-03 23:46 UTC (permalink / raw)
  To: gcc-bugs

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
     };

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-05-09 19:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
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

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).