https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107206
Bug ID: 107206 Summary: Bogus -Wuninitialized in std::optional Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- Since 12, at -std=c++17 -O -Wuninitialized: #include <optional> struct X { X() = default; X(X const& r) : i(r.i) {} int i; }; struct Y { Y() : x() {} X x; std::optional<int> o; }; struct Z { Y y; explicit Z(Y y) : y(y) {} }; void f(Y const&); void test() { Y const y; Z z(y); z.y.o = 1; auto const w = z; f(w.y); } In copy constructor 'Y::Y(const Y&)', inlined from 'void test()' at <source>:19:10: <source>:7:8: warning: '*(int*)((char*)&y + offsetof(const Y, Y::o.std::optional<int>::<unnamed>.std::_Optional_base<int, true, true>::<unnamed>))' is used uninitialized [-Wuninitialized] 7 | struct Y { | ^ <source>: In function 'void test()': <source>:18:13: note: 'y' declared here 18 | Y const y; | ^ Most similar to #80635 and #86465, I think? Although this is -Wuninitialized, not -Wmaybe-uninitialized.