https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
Chris Uzdavinis <cuzdav at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cuzdav at gmail dot com
--- Comment #54 from Chris Uzdavinis <cuzdav at gmail dot com> ---
I'm not sure if this is the same bug or a different one, but it's in the same
family (I think). Visible in current trunk, 10.2 release, and as far back as
8.1.
I found optimize level -Os is necessary
https://godbolt.org/z/Ta55jM
#include <optional>
using Opt = std::optional<int>;
Opt f(int x) {
Opt ret;
Opt val = (x == 1) ? 999 : (x == 2) ? Opt(2) : std::nullopt;
if (val.has_value())
ret = val.value();
return ret;
}
<source>: In function 'Opt f(int)':
<source>:9:12: error: 'val.std::_Optional_payload_base<int>::_Storage<int,
true>::_M_value' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
9 | return ret;
| ^~~