https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465
Bug ID: 86465 Summary: C++17 <optional> triggers: ‘<anonymous>’ may be used uninitialized in this function Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: proski at gnu dot org Target Milestone: --- Created attachment 44378 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44378&action=edit Preprocessed test case The attached file triggers a warning: $ g++ -std=c++17 -Wall -O2 -c optional.cpp -save-temps optional.cpp: In member function ‘virtual std::optional<int> Child::get_hairy_value()’: optional.cpp:20:25: warning: ‘<anonymous>’ may be used uninitialized in this function [-Wmaybe-uninitialized] return {}; ^ The issue is observed with gcc 8 as packaged by Fedora (gcc-8.1.1-1.fc28.x86_64) and with the current gcc trunk (commit c85ec25b97e485c6f3493fc42c473db2a11ac9ea). gcc 7.3.0 doesn't exhibit the bug. Interestingly, the preprocessed file generated by gcc 7.3.0 doesn't trigger the warning in gcc 8 or 9. Also, the warning goes away if experimental/optional is used, so C++17 is required to reproduce it. Optimization (at least -O1) is required to trigger the warning.