Bug 92092 - Spurious warning: '<anonymous>' may be used uninitialized in this function
Summary: Spurious warning: '<anonymous>' may be used uninitialized in this function
Status: RESOLVED DUPLICATE of bug 92700
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-14 20:22 UTC by Corey Kosak
Modified: 2025-09-04 22:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Corey Kosak 2019-10-14 20:22:57 UTC
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;
}
Comment 1 Jonathan Wakely 2019-10-14 22:53:12 UTC
dup

*** This bug has been marked as a duplicate of bug 80635 ***
Comment 2 Andrew Pinski 2025-09-04 22:55:20 UTC
Same issue as PR 92700.

*** This bug has been marked as a duplicate of bug 92700 ***