<div dir="auto"><div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 22 Jun 2026, 23:56 Nathan Myers, <<a href="mailto:ncm@cantrip.org">ncm@cantrip.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">GCC 16.1's explicit specialization of std::allocator_traits on<br>
std::pmr::polymorphic_allocator<T> lacks the required<br>
definition of allocate_at_least. This patch provides it, and<br>
tests for its presence in C++23 and up.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">OK for gcc-16</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
libstdc++-v3/Changelog:<br>
        PR libstdc++/125890<br>
        * include/bits/memory_resource.h (allocate_at_least): Add to<br>
        allocator_traits<pmr::polymorphic_allocator> specialization.<br>
        * testsuite/20_util/polymorphic_allocator/at_least.cc: New test.<br>
---<br>
 libstdc++-v3/include/bits/memory_resource.h   | 17 +++++++++++++<br>
 .../20_util/polymorphic_allocator/at_least.cc | 25 +++++++++++++++++++<br>
 2 files changed, 42 insertions(+)<br>
 create mode 100644 libstdc++-v3/testsuite/20_util/polymorphic_allocator/at_least.cc<br>
<br>
diff --git a/libstdc++-v3/include/bits/memory_resource.h b/libstdc++-v3/include/bits/memory_resource.h<br>
index e5c6697b07e..a9db58b76a3 100644<br>
--- a/libstdc++-v3/include/bits/memory_resource.h<br>
+++ b/libstdc++-v3/include/bits/memory_resource.h<br>
@@ -48,6 +48,7 @@<br>
 # include <bits/utility.h>             // index_sequence<br>
 # include <tuple>                      // tuple, forward_as_tuple<br>
 #endif<br>
+#include <bits/memoryfwd.h><br>
<br>
 namespace std _GLIBCXX_VISIBILITY(default)<br>
 {<br>
@@ -468,6 +469,22 @@ namespace pmr<br>
       allocate(allocator_type& __a, size_type __n, const_void_pointer)<br>
       { return __a.allocate(__n); }<br>
<br>
+#ifdef __glibcxx_allocate_at_least<br>
+      /**<br>
+       *  @brief  Allocate memory.<br>
+       *  @param  __a  An allocator.<br>
+       *  @param  __n  The number of objects to allocate space for.<br>
+       *  @return Memory of suitable size and alignment for `n` objects<br>
+       *          of type `value_type`.<br>
+       *<br>
+       *  Just returns `{ a.allocate(n), n }`: `polymorphic_allocator`<br>
+       *  cannot be extended without breaking ABI.<br>
+      */<br>
+      [[nodiscard]] static std::allocation_result<pointer, size_type><br>
+      allocate_at_least(allocator_type& __a, size_type __n)<br>
+      { return { __a.allocate(__n), __n }; }<br>
+#endif<br>
+<br>
       /**<br>
        *  @brief  Deallocate memory.<br>
        *  @param  __a  An allocator.<br>
diff --git a/libstdc++-v3/testsuite/20_util/polymorphic_allocator/at_least.cc b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/at_least.cc<br>
new file mode 100644<br>
index 00000000000..2910807d030<br>
--- /dev/null<br>
+++ b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/at_least.cc<br>
@@ -0,0 +1,25 @@<br>
+// { dg-do run { target c++23 } }<br>
+<br>
+#include <memory_resource><br>
+#include <testsuite_hooks.h><br>
+#include <testsuite_allocator.h><br>
+<br>
+void<br>
+alloc_at_least()<br>
+{<br>
+  struct A { char a; };<br>
+  using alloc_A = std::pmr::polymorphic_allocator<A>;<br>
+  using traits_A = std::allocator_traits<alloc_A>;<br>
+  alloc_A alloc_a;<br>
+  // This just forwards to alloc_a::allocate:<br>
+  std::allocation_result result = traits_A::allocate_at_least(alloc_a, 1);<br>
+  VERIFY(result.count == 1);<br>
+  VERIFY(result.ptr != nullptr);<br>
+  auto [pointer, count] = result;<br>
+  traits_A::deallocate(alloc_a, pointer, count);<br>
+}<br>
+<br>
+int main()<br>
+{<br>
+  alloc_at_least();<br>
+}<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div></div></div>