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

            Bug ID: 92092
           Summary: Spurious warning: '<anonymous>' may be used
                    uninitialized in this function
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu at kosak dot com
  Target Milestone: ---

Hello,

The program below gets the following warning message. I think the program is
well-formed (Clang 9.0.0 accepts it without warning).

** Compiler Flags **

-O2 -std=c++17 -Wall 

** Version **

gcc 9.2.0, tested online with Compiler Explorer ( https://gcc.godbolt.org/ )
but the warning happens on my Ubuntu machine as well (that version is gcc
8.3.0)

** Warning **

source>: In static member function 'static _Res
std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const
std::_Any_data&, _ArgTypes&& ...) [with _Res = std::optional<Color>; _Functor =
main()::<lambda()>; _ArgTypes = {}]':

<source>:13:33: warning: '<anonymous>' may be used uninitialized in this
function [-Wmaybe-uninitialized]

   13 |     return std::optional<Color>();


** Source code **

#include <functional>
#include <optional>

enum class Color { Red, Green, Blue };
size_t load(size_t);

int main() {
  size_t currentValue = load(0);
  auto ready = [currentValue]() -> std::optional<Color> {
    if (load(1) != currentValue) {
      return Color::Red;
    }
    return std::optional<Color>();
  };
  std::function<std::optional<Color>()> temp(ready);
  (void)temp;
}

Reply via email to