public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable
@ 2022-04-28 13:29 byteslice at airmail dot cc
  2022-04-29  6:33 ` [Bug tree-optimization/105423] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: byteslice at airmail dot cc @ 2022-04-28 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105423
           Summary: Bogus -Werror=maybe-uninitialized with definitely
                    initialized variable
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: byteslice at airmail dot cc
  Target Milestone: ---

Created attachment 52896
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52896&action=edit
Cvised example

On gcc 12.0.1 20220413 (Fedora 36 Beta), with c++ -O1
-Werror=maybe-uninitialized, the attachment fails to compile, with the
following message:

In member function 'void std::Trans_NS___cxx11_basic_string<_CharT,
<template-parameter-1-2>, <template-parameter-1-3> >::_S_copy(_CharT*) [with
_CharT = char; _Traits = std::char_traits; <template-parameter-1-3> = char]',
    inlined from 'constexpr std::Trans_NS___cxx11_basic_string<_CharT, _Traits,
_Alloc>& std::Trans_NS___cxx11_basic_string<_CharT, <template-parameter-1-2>,
<template-parameter-1-3> >::_M_replace(const _CharT*, long int) [with _CharT =
char; _Traits = std::char_traits; <template-parameter-1-3> = char]' at
<source>:49:12,
    inlined from 'void std::Trans_NS___cxx11_basic_string<_CharT,
<template-parameter-1-2>, <template-parameter-1-3> >::operator=(const _CharT*)
[with _CharT = char; _Traits = std::char_traits; <template-parameter-1-3> =
char]' at <source>:40:15,
    inlined from 'void Shuffle()' at <source>:55:8:
<source>:36:46: error: '((char*)((char*)&mask +
offsetof(std::Trans_NS___cxx11_basic_string<char, std::char_traits,
char>,std::Trans_NS___cxx11_basic_string<char, std::char_traits,
char>::<unnamed>)))[2]' may be used uninitialized [-Werror=maybe-uninitialized]
   36 |   void _S_copy(_CharT *__s) { _Traits::assign(_S_copy___d, *__s); }
      |                               ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
<source>: In function 'void Shuffle()':
<source>:54:44: note: 'mask' declared here
   54 |   std::Trans_NS___cxx11_basic_string<char> mask{};
      |                                            ^~~~
In member function 'void std::Trans_NS___cxx11_basic_string<_CharT,
<template-parameter-1-2>, <template-parameter-1-3> >::_S_copy(_CharT*) [with
_CharT = char; _Traits = std::char_traits; <template-parameter-1-3> = char]',
    inlined from 'constexpr std::Trans_NS___cxx11_basic_string<_CharT, _Traits,
_Alloc>& std::Trans_NS___cxx11_basic_string<_CharT, <template-parameter-1-2>,
<template-parameter-1-3> >::_M_replace(const _CharT*, long int) [with _CharT =
char; _Traits = std::char_traits; <template-parameter-1-3> = char]' at
<source>:49:12,
    inlined from 'void std::Trans_NS___cxx11_basic_string<_CharT,
<template-parameter-1-2>, <template-parameter-1-3> >::operator=(const _CharT*)
[with _CharT = char; _Traits = std::char_traits; <template-parameter-1-3> =
char]' at <source>:40:15,
    inlined from 'void Shuffle()' at <source>:55:8:
<source>:36:47: error:
'mask.std::Trans_NS___cxx11_basic_string<char>::_S_copy___d' may be used
uninitialized [-Werror=maybe-uninitialized]
   36 |   void _S_copy(_CharT *__s) { _Traits::assign(_S_copy___d, *__s); }
      |                                               ^~~~~~~~~~~
<source>: In function 'void Shuffle()':
<source>:54:44: note: 'mask' declared here
   54 |   std::Trans_NS___cxx11_basic_string<char> mask{};
      |                                            ^~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1

This warning is bogus because the variable mask is default brace-initialized
and thus its member _S_copy___d is also initialized. The bogus warning does not
appear in older versions of GCC.

Adding -fno-inline to options allows compilation to succeed.

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

* [Bug tree-optimization/105423] Bogus -Werror=maybe-uninitialized with definitely initialized variable
  2022-04-28 13:29 [Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable byteslice at airmail dot cc
@ 2022-04-29  6:33 ` rguenth at gcc dot gnu.org
  2022-04-29 11:27 ` byteslice at airmail dot cc
  2022-10-31 23:45 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-29  6:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
             Blocks|                            |24639
   Last reconfirmed|                            |2022-04-29

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm getting

> ~/install/gcc-12/usr/local/bin/g++ -S t.ii -O  -Werror=maybe-uninitialized
t.ii: In instantiation of 'std::Trans_NS___cxx11_basic_string<_CharT,
<template-parameter-1-2>, <template-parameter-1-3>
>::Trans_NS___cxx11_basic_string() [with _CharT = char; _Traits =
std::char_traits; <template-parameter-1-3> = char]':
t.ii:54:49:   required from here
t.ii:37:37: error: no matching function for call to
'std::Trans_NS___cxx11_basic_string<char>::<unnamed
struct>::._anon_0(std::allocator_traits<std::allocator<char> >::pointer)'
   37 |   Trans_NS___cxx11_basic_string() : _M_dataplus(_M_local_data()) {}
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.ii:25:10: note: candidate:
'std::Trans_NS___cxx11_basic_string<char>::<unnamed struct>::<constructor>()'
   25 |   struct {
      |          ^
t.ii:25:10: note:   candidate expects 0 arguments, 1 provided
...

so the testcase doesn't compile for me


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

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

* [Bug tree-optimization/105423] Bogus -Werror=maybe-uninitialized with definitely initialized variable
  2022-04-28 13:29 [Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable byteslice at airmail dot cc
  2022-04-29  6:33 ` [Bug tree-optimization/105423] " rguenth at gcc dot gnu.org
@ 2022-04-29 11:27 ` byteslice at airmail dot cc
  2022-10-31 23:45 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: byteslice at airmail dot cc @ 2022-04-29 11:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Liam White <byteslice at airmail dot cc> ---
My bad, use -std=c++20 as well for this example. Then you should reproduce the
issue.

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

* [Bug tree-optimization/105423] Bogus -Werror=maybe-uninitialized with definitely initialized variable
  2022-04-28 13:29 [Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable byteslice at airmail dot cc
  2022-04-29  6:33 ` [Bug tree-optimization/105423] " rguenth at gcc dot gnu.org
  2022-04-29 11:27 ` byteslice at airmail dot cc
@ 2022-10-31 23:45 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-31 23:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|1                           |0
             Status|WAITING                     |UNCONFIRMED

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

end of thread, other threads:[~2022-10-31 23:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 13:29 [Bug tree-optimization/105423] New: Bogus -Werror=maybe-uninitialized with definitely initialized variable byteslice at airmail dot cc
2022-04-29  6:33 ` [Bug tree-optimization/105423] " rguenth at gcc dot gnu.org
2022-04-29 11:27 ` byteslice at airmail dot cc
2022-10-31 23:45 ` pinskia 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).