https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127005
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrea Pinski <[email protected]>: https://gcc.gnu.org/g:e982f847aab9f76a35ec70ff53aca548abe2331e commit r17-3656-ge982f847aab9f76a35ec70ff53aca548abe2331e Author: Andrea Pinski <[email protected]> Date: Sat Aug 22 22:09:20 2026 -0700 libstdc++: optional: Treat _M_engaged as being assumed to be false after the destructor [PR127005] Sometimes the destructor will cause the optimizers not to see that _M_engaged has been to set to false (e.g. an external call). This means that we might get an uninitialized warning after the destructor in some cases. Adding `if (_M_engaged) __builtin_unreachable(); ` after the destructor will allow for the optimizations to know that the value of _M_engaged is 0 afterwards. This helps with optimizations and the uninitialized warning. PR libstdc++/127005 libstdc++-v3/ChangeLog: * include/std/optional (optional::_M_destroy): Add an assumption on _M_engaged being false after the destructor call. gcc/testsuite/ChangeLog: * g++.dg/warn/Wuninitialized-36.C: New test. Signed-off-by: Andrea Pinski <[email protected]>
