Landing: f3e63a9fb3b4

Project / Subsystem

gcc / libstdc++

Date

2026-04-18

Author

Patrick Palka

Commit

f3e63a9fb3b40f81b794b369a1ab616f01e69730

Source

github

Impact

6/10

Perf win

No

Breaking

No

All attributes

project
gcc
subsystem
libstdc++
patch_id
commit_hash
f3e63a9fb3b40f81b794b369a1ab616f01e69730
source_type
github
headline
Libstdc++: Fix constantness of engaged -> disengaged std::optional.
tldr
Clearing a `std::optional` in C++23 now maintains constant expression requirements, fixing a compile-time error.
why_it_matters
Corrects a subtle violation of constant expression rules in C++23, which could prevent `std::optional` from being used in constant initializers, impacting metaprogramming and compile-time computations.
author
Patrick Palka
impact_score
6
impact_rationale
Fixes a subtle correctness issue affecting constant expression evaluation, which can impact code using `std::optional` in metaprogramming contexts.
outcome
committed
performance_win
false
breaking_change
false
series_id
series_parts
[]
tags
  • libstdc++
  • constexpr
  • optional
  • C++23
discussion_id_link
bugzilla_pr
date
2026-04-18T00:00:00.000Z

When a std::optional containing a value is cleared, the destructor of the contained value is invoked, potentially leaving the union without an active member during constant evaluation. This violates constant expression requirements, diagnosed by Clang and recent GCC versions. This patch activates a dummy union member after destroying the value to ensure the union always has an active member and uses std::construct_at to avoid a front-end bug.