public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present.
@ 2021-10-17 12:47 calin.culianu at bitcoincashnode dot org
  2021-10-17 16:43 ` [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: calin.culianu at bitcoincashnode dot org @ 2021-10-17 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102801
           Summary: Incorrect -Wmaybe-uninitialized warning/interation for
                    a std::optional only when a nested struct is also
                    present.
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: calin.culianu at bitcoincashnode dot org
  Target Milestone: ---

Created attachment 51617
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51617&action=edit
Test case where a spurious/incorrect -Wmaybe-uninitialized warning is generated

Hi -- I noticed a regression in GCC 10 and GCC 11 related to `std::optional`. 
The attached file, if compiled with `-O2 -Wall -std=c++17 -c` as options, will
warn incorrectly about uninitialized members on both GCC 10 and GCC 11 (I
haven't tried 9 yet but I think 8 & 9 are ok).

Note that the key element in the below code is the nested `struct Shared`. If
that is omitted, no warnings occur.

Attached code warns erroneously (GCC 10 & 11):

    g++ -O2 -Wall -std=c++17 -c warn3.cpp


Attached code does not warn (nested struct omitted):

    g++ -DNO_WARN -O2 -Wall -std=c++17 -c warn3.cpp

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

* [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction for a std::optional only when a nested struct is also present.
  2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
@ 2021-10-17 16:43 ` redi at gcc dot gnu.org
  2021-10-17 20:33 ` egallager at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-17 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
7, 8, 9 and 10 all warn:

mozilla_jwakely0/warn3.cpp: In function 'void foo(Q<C2>&, std::vector<C2>&)':
mozilla_jwakely0/warn3.cpp:8:7: warning: '<anonymous>.C::b' may be used
uninitialized in this function [-Wmaybe-uninitialized]
    8 | class C {
      |       ^

11 and trunk warn about that and also:

/home/jwakely/gcc/12/include/c++/12.0.0/bits/shared_ptr_base.h:709:19: warning:
'((const std::__shared_count<__gnu_cxx::_S_atomic>*)((char*)&<unnamed> +
offsetof(C2, C2::c.std::optional<C>::<unnamed>.std::_Optional_base<C, false,
false>::_M_payload.std::_Optional_payload<C, false, false,
false>::<unnamed>.std::_Optional_payload<C, true, false,
false>::<unnamed>.std::_Optional_payload_base<C>::_M_payload)))[2].std::__shared_count<>::_M_pi'
may be used uninitialized [-Wmaybe-uninitialized]
  709 |       : _M_pi(__r._M_pi)
      |               ~~~~^~~~~

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

* [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction for a std::optional only when a nested struct is also present.
  2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
  2021-10-17 16:43 ` [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction " redi at gcc dot gnu.org
@ 2021-10-17 20:33 ` egallager at gcc dot gnu.org
  2021-10-17 21:59 ` calin.culianu at bitcoincashnode dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-10-17 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |24639
           Keywords|                            |diagnostic
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
Is this related to and/or a dup of bug 80635?


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] 6+ messages in thread

* [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction for a std::optional only when a nested struct is also present.
  2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
  2021-10-17 16:43 ` [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction " redi at gcc dot gnu.org
  2021-10-17 20:33 ` egallager at gcc dot gnu.org
@ 2021-10-17 21:59 ` calin.culianu at bitcoincashnode dot org
  2022-09-22 13:18 ` [Bug tree-optimization/102801] " rguenth at gcc dot gnu.org
  2022-09-22 13:19 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: calin.culianu at bitcoincashnode dot org @ 2021-10-17 21:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Calin Culianu <calin.culianu at bitcoincashnode dot org> ---
@Eric Gallager : Initially I came across that bug and it looked eerily similar
to this one. I am not a gcc dev, just a user of gcc. No idea.. but yeah looks
like in some situations certainly gcc has trouble with this uninitialized
warning when std::optional enters the picture...

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

* [Bug tree-optimization/102801] Incorrect -Wmaybe-uninitialized warning/interaction for a std::optional only when a nested struct is also present.
  2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
                   ` (2 preceding siblings ...)
  2021-10-17 21:59 ` calin.culianu at bitcoincashnode dot org
@ 2022-09-22 13:18 ` rguenth at gcc dot gnu.org
  2022-09-22 13:19 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-22 13:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.2.1, 13.0
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The testcase no longer warns after GCC 12.2 or on GCC 13 trunk for me.  I can
re-confirm diagnostics with GCC 10 and GCC 11.  I'm going to add the testcase
and close this bug.

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

* [Bug tree-optimization/102801] Incorrect -Wmaybe-uninitialized warning/interaction for a std::optional only when a nested struct is also present.
  2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
                   ` (3 preceding siblings ...)
  2022-09-22 13:18 ` [Bug tree-optimization/102801] " rguenth at gcc dot gnu.org
@ 2022-09-22 13:19 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-22 13:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:44dba051d72587828882cbb31118934a4fb06c1a

commit r13-2776-g44dba051d72587828882cbb31118934a4fb06c1a
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Sep 22 15:18:47 2022 +0200

    tree-optimization/102801 - testcase for uninit diagnostic

    The following testcase is fixed in GCC 12+

            PR tree-optimization/102801
    gcc/testsuite/
            * g++.dg/warn/Wuninitialized-33.C: New testcase.

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-17 12:47 [Bug c++/102801] New: Incorrect -Wmaybe-uninitialized warning/interation for a std::optional only when a nested struct is also present calin.culianu at bitcoincashnode dot org
2021-10-17 16:43 ` [Bug c++/102801] Incorrect -Wmaybe-uninitialized warning/interaction " redi at gcc dot gnu.org
2021-10-17 20:33 ` egallager at gcc dot gnu.org
2021-10-17 21:59 ` calin.culianu at bitcoincashnode dot org
2022-09-22 13:18 ` [Bug tree-optimization/102801] " rguenth at gcc dot gnu.org
2022-09-22 13:19 ` cvs-commit 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).