[gcc r16-8777] libstdc++: Restrict engaged -> disengaged std::optional fix [PR124910]

Patrick Palka ppalka@gcc.gnu.org
Tue Apr 21 13:34:43 GMT 2026


https://gcc.gnu.org/g:d92712cdcb19a8e0c6668880b2443a3a18d983da

commit r16-8777-gd92712cdcb19a8e0c6668880b2443a3a18d983da
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 21 09:33:50 2026 -0400

    libstdc++: Restrict engaged -> disengaged std::optional fix [PR124910]
    
    It turns out a union without an active member does not violate C++20 core
    constant expression rules and r16-8748 was really just a workaround for a
    front end bug.  The actual underlying problem -- that the constexpr
    evaluator treated an explicitly destroyed union member as still active --
    has been fixed by r16-8767 which makes this workaround unnecessary for GCC.
    Rather than remove the workaround, restrict it to Clang which seems to have
    a similar bug making it still needed for e.g. the r16-8748 testcase.
    
            PR c++/124910
    
    libstdc++-v3/ChangeLog:
    
            * include/std/optional (_Optional_payload_base::_M_destroy):
            Restrict r16-8748 workaround to Clang, and adjust comment.
    
    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>

Diff:
---
 libstdc++-v3/include/std/optional | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index 49ba7b6b45dd..b9cc019feff7 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -321,10 +321,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	_M_engaged = false;
 	_M_payload._M_value.~_Stored_type();
-#if __cpp_lib_optional >= 202106L // full constexpr support
+#if defined(__clang__) && __cpp_lib_optional >= 202106L // full constexpr support
 	if (std::is_constant_evaluated())
-	  // Ensure union _M_payload always has an active member, for sake
-	  // of the core constant expression requirements.
+	  // Work around PR124910 for Clang.
 	  std::construct_at(std::__addressof(_M_payload._M_empty));
 #endif
       }


More information about the Libstdc++-cvs mailing list