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

Reply via email to