Landing: e982f847aab9
Project / Subsystem
gcc / libstdc++
Date
2026-08-23
Author
Andrea Pinski
Commit
e982f847aab9f76a35ec70ff53aca548abe2331e
Source
github
Perf win
No
Breaking
No
All attributes
- project
- gcc
- subsystem
- libstdc++
- patch_id
- —
- commit_hash
- e982f847aab9f76a35ec70ff53aca548abe2331e
- source_type
- github
- headline
- libstdc++: optional: Treat _M_engaged as false after destructor
- tldr
- Improves optimization and reduces uninitialized warnings for std::optional by assuming _M_engaged is false after destruction.
- author
- Andrea Pinski
- outcome
- committed
- performance_win
- false
- breaking_change
- false
- series_id
- —
- series_parts
- []
- tags
-
- • libstdc++
- • optimization
- • warning
- discussion_id_link
- —
- bugzilla_pr
- —
- date
- 2026-08-23T00:00:00.000Z
GCC’s optimizer sometimes failed to recognize that the _M_engaged flag in std::optional is false after its destructor runs, especially if the destructor involved external calls. This could lead to uninitialized warnings. This commit adds a __builtin_unreachable() call after the destructor if _M_engaged is still true, explicitly informing the optimizer that _M_engaged must be false post-destruction. This helps prevent spurious warnings and improves optimization. This fixes PR127005.