https://gcc.gnu.org/g:874605e8c44ca4823cedb2881cdbd91f38cff5bc

commit r17-2453-g874605e8c44ca4823cedb2881cdbd91f38cff5bc
Author: Jakub Jelinek <[email protected]>
Date:   Thu Jul 16 13:58:52 2026 +0200

    libstdc++: Mark std::indirect and std::polymorphic with 
_GLIBCXX_NO_SPECIALIZATIONS [PR120635]
    
    The following marks these two templates with [[_Clang::no_specializations]]
    because the P3019R14 paper which introduced them already added the
    restrictions that they shouldn't be specialized by users.
    
    I think I'll defer the rest to others (i.e. P2652R2 - std::allocator_traits,
    P0912R5 - std::coroutine_handle and LWG4535 - <simd>).
    
    2026-07-16  Jakub Jelinek  <[email protected]>
    
            PR c++/120635
            * include/bits/indirect.h (std::indirect, std::polymorphic): Add
            _GLIBCXX_NO_SPECIALIZATIONS.
            * testsuite/std/memory/indirect/specialization.cc: New test.
            * testsuite/std/memory/polymorphic/specialization.cc: New test.
    
    Reviewed-by: Jonathan Wakely <[email protected]>

Diff:
---
 libstdc++-v3/include/bits/indirect.h                        |  4 ++--
 .../testsuite/std/memory/indirect/specialization.cc         | 13 +++++++++++++
 .../testsuite/std/memory/polymorphic/specialization.cc      | 13 +++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/indirect.h 
b/libstdc++-v3/include/bits/indirect.h
index 5be6713eaf3f..cb6e9535a8e1 100644
--- a/libstdc++-v3/include/bits/indirect.h
+++ b/libstdc++-v3/include/bits/indirect.h
@@ -68,7 +68,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // [indirect], class template indirect
   template<typename _Tp, typename _Alloc>
-    class indirect
+    class _GLIBCXX_NO_SPECIALIZATIONS indirect
     {
       static_assert(is_object_v<_Tp>);
       static_assert(!is_array_v<_Tp>);
@@ -467,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // [polymorphic], class template polymorphic
   template<typename _Tp, typename _Alloc>
-    class polymorphic
+    class _GLIBCXX_NO_SPECIALIZATIONS polymorphic
     {
       static_assert(is_object_v<_Tp>);
       static_assert(!is_array_v<_Tp>);
diff --git a/libstdc++-v3/testsuite/std/memory/indirect/specialization.cc 
b/libstdc++-v3/testsuite/std/memory/indirect/specialization.cc
new file mode 100644
index 000000000000..4a32975238b5
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/memory/indirect/specialization.cc
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++26 } }
+
+#include <memory>
+
+struct A {};
+template<typename T>
+struct B {};
+
+template<>
+class std::indirect<A, std::pmr::polymorphic_allocator <A>> {};                
// { dg-error "cannot be specialized" }
+
+template<typename T>
+class std::indirect<B<T>, std::pmr::polymorphic_allocator <B<T>>> {};  // { 
dg-error "cannot be specialized" }
diff --git a/libstdc++-v3/testsuite/std/memory/polymorphic/specialization.cc 
b/libstdc++-v3/testsuite/std/memory/polymorphic/specialization.cc
new file mode 100644
index 000000000000..2247f1b9bd1d
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/memory/polymorphic/specialization.cc
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++26 } }
+
+#include <memory>
+
+struct A {};
+template<typename T>
+struct B {};
+
+template<>
+class std::polymorphic<A, std::pmr::polymorphic_allocator <A>> {};             
// { dg-error "cannot be specialized" }
+
+template<typename T>
+class std::polymorphic<B<T>, std::pmr::polymorphic_allocator <B<T>>> {};       
// { dg-error "cannot be specialized" }

Reply via email to