From 83cae6c4b788544635a71748e1881c150f42efef Mon Sep 17 00:00:00 2001
From: Jonathan Wakely <jwakely@redhat.com>
Date: Tue, 4 Jul 2023 16:03:45 +0100
Subject: [PATCH] libstdc++: Fix std::__uninitialized_default_n for constant
 evaluation [PR110542]

libstdc++-v3/ChangeLog:

	PR libstdc++/110542
	* include/bits/stl_uninitialized.h (__uninitialized_default_n):
	Do not use std::fill_n during constant evaluation.
---
 libstdc++-v3/include/bits/stl_uninitialized.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h
index 6752c6b57466..be7b4afdd05f 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -695,6 +695,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline _ForwardIterator
     __uninitialized_default_n(_ForwardIterator __first, _Size __n)
     {
+#ifdef __cpp_lib_is_constant_evaluated
+      if (std::is_constant_evaluated())
+	return __uninitialized_default_n_1<false>::
+		 __uninit_default_n(__first, __n);
+#endif
+
       typedef typename iterator_traits<_ForwardIterator>::value_type
 	_ValueType;
       // See uninitialized_fill_n for the conditions for using std::fill_n.
-- 
GitLab