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

            Bug ID: 92700
           Summary: wrong "unintialized" warning with std::optional
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenb...@fh-soft.de
  Target Milestone: ---

#include <optional>
#include <string>

int e;

template <typename T> std::optional <size_t> f ()
{
  if (auto i = std::string ().find ('a'))
    return i;
  return { };
}

int main ()
{
  size_t j = 1;
  while (j)
    {
      auto i = f <int> ();
      if (e != 1 && e != 4 && e != 7)
        throw 0;
      if (i)
        j = *i;
    }
}

% g++-9 --version
g++-9 (GCC) 9.1.0

% g++-9 --std=c++17 test.cpp -Wall -O3
test.cpp: In function 'int main()':
test.cpp:10:12: warning: '<anonymous>' may be used uninitialized in this
function [-Wmaybe-uninitialized]

This may be a duplicate, but I can't really tell since this warning seems to
depend on many seemingly unrelated conditions, e.g. f must be a template,
std::string::find seems required (at least a simple external function won't
do),
the seemingly unrelated test of e is required (and must contain at least
3 clauses with specific values -- 1, 2, 3 won't do).

Reply via email to