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

* [Bug libstdc++/103549] [12 regression] Uninitialized member warning from regex header
  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 ` redi at gcc dot gnu.org
  2021-12-04 15:55 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-04  1:00 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-04
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think this is intentional, or at least not a bug. The match_results type
can't be used for much until it's "ready" and the member will be set then.

But it looks like this would read the indeterminate value:

cmatch m1, m2;
m1.swap(m2);

So we should initialize it as you suggest.

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

* [Bug libstdc++/103549] [12 regression] Uninitialized member warning from regex header
  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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-04 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:87710ec7b213245ecb194b778e97ae3a6790394f

commit r12-5792-g87710ec7b213245ecb194b778e97ae3a6790394f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Dec 4 11:38:25 2021 +0000

    libstdc++: Initialize member in std::match_results [PR103549]

    This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

    Also name the template parameters in the forward declaration, to get rid
    of the <template-parameter-1-1> noise in diagnostics.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103549
            * include/bits/regex.h (match_results): Give names to template
            parameters in first declaration.
            (match_results::_M_begin): Add default member-initializer.

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

* [Bug libstdc++/103549] [12 regression] Uninitialized member warning from regex header
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-12-06  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (2 preceding siblings ...)
  2021-12-06  8:21 ` rguenth at gcc dot gnu.org
@ 2021-12-06 10:39 ` redi at gcc dot gnu.org
  2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-06 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12 regression]             |Uninitialized member
                   |Uninitialized member        |warning from regex header
                   |warning from regex header   |

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk, but I'll backport it too.

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-05 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:5e0ef5621b518caa593b77b7c8f202ee018a0900

commit r11-9437-g5e0ef5621b518caa593b77b7c8f202ee018a0900
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Dec 4 11:38:25 2021 +0000

    libstdc++: Initialize member in std::match_results [PR103549]

    This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

    Also name the template parameters in the forward declaration, to get rid
    of the <template-parameter-1-1> noise in diagnostics.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103549
            * include/bits/regex.h (match_results): Give names to template
            parameters in first declaration.
            (match_results::_M_begin): Add default member-initializer.

    (cherry picked from commit 87710ec7b213245ecb194b778e97ae3a6790394f)

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-05 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:17af7c1a054c9663e5b353a4fc576522e0cd9a4f

commit r10-10379-g17af7c1a054c9663e5b353a4fc576522e0cd9a4f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Dec 4 11:38:25 2021 +0000

    libstdc++: Initialize member in std::match_results [PR103549]

    This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

    Also name the template parameters in the forward declaration, to get rid
    of the <template-parameter-1-1> noise in diagnostics.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103549
            * include/bits/regex.h (match_results): Give names to template
            parameters in first declaration.
            (match_results::_M_begin): Add default member-initializer.

    (cherry picked from commit 87710ec7b213245ecb194b778e97ae3a6790394f)

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-05 22:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|12.0                        |10.4
             Status|NEW                         |RESOLVED

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.3 and 10.4

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-09 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:756d1581d11c583d9cbfc2e0b7ce1a095845085e

commit r9-10055-g756d1581d11c583d9cbfc2e0b7ce1a095845085e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Dec 4 11:38:25 2021 +0000

    libstdc++: Initialize member in std::match_results [PR103549]

    This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

    Also name the template parameters in the forward declaration, to get rid
    of the <template-parameter-1-1> noise in diagnostics.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103549
            * include/bits/regex.h (match_results): Give names to template
            parameters in first declaration.
            (match_results::_M_begin): Add default member-initializer.

    (cherry picked from commit 87710ec7b213245ecb194b778e97ae3a6790394f)

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

* [Bug libstdc++/103549] Uninitialized member warning from regex header
  2021-12-03 23:46 [Bug libstdc++/103549] New: [12 regression] Uninitialized member warning from regex header sss@li-snyder.org
                   ` (7 preceding siblings ...)
  2022-05-09 16:39 ` cvs-commit at gcc dot gnu.org
@ 2022-05-09 19:44 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-09 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |9.5

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And 9.5

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