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

            Bug ID: 103989
           Summary: [12 regression] std::optional and bogus
                    -Wmaybe-unitialized at -Og
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m...@nieper-wisskirchen.de
  Target Milestone: ---

With the trunk version of GCC compiling the following program with 

-std=c++17 -Og -Wall -Werror

gives a bogus maybe-uninitialized error (in the standard library component for
the shared pointer):

////
#include <optional>
#include <memory>

struct A {
  A (int a) : a {a} 
  {}

  const std::shared_ptr <int> x;
  int a;
};

class B
{
public:
  B (const std::optional <A>& a)
    : a {a}
  {
  }
public:
  const std::optional <A> a;
};

int
main ()
{
  B b {std::nullopt};
}
////

Compiling it with

-std=c++17 -O1 -Wall -Werror

doesn't produce the error.

As the code compiles find at -Og and -O1 with GCC 11.2, this is a regression.

The error triggering is brittle. It goes away if the dummy member variable a in
class A is removed, for example.

For experimentation, the test case can be found here:
https://godbolt.org/z/arGKT7d5n.

Reply via email to