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

commit r16-8967-gca5c9ec549009b95cc6a322db3ee10b3fed377e7
Author: Jonathan Wakely <[email protected]>
Date:   Tue May 26 10:50:53 2026 +0100

    libstdc++: Fix <optional> for freestanding [PR125450]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/125450
            * include/std/optional (range_format): Do not define for
            freestanding.
    
    (cherry picked from commit 23b9ac257cf508bc4fa479c82fcfc768c4abcd79)

Diff:
---
 libstdc++-v3/include/std/optional | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index e3c6ea209889..9f03d3e89414 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -60,7 +60,9 @@
 # include <concepts>
 #endif
 #ifdef __cpp_lib_optional_range_support // C++ >= 26
-# include <bits/formatfwd.h>
+# if _GLIBCXX_HOSTED
+#  include <bits/formatfwd.h>
+# endif
 # include <bits/ranges_base.h>
 # include <bits/stl_iterator.h>
 #endif
@@ -2285,9 +2287,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     ranges::enable_borrowed_range<optional<_Tp&>> = true;
 #endif
 
+#if _GLIBCXX_HOSTED
   template<typename _Tp>
     inline constexpr range_format
       format_kind<optional<_Tp>> = range_format::disabled;
+#endif
 #endif // __cpp_lib_optional_range_support
 
 #undef _GLIBCXX_USE_CONSTRAINTS_FOR_OPTIONAL

Reply via email to