[gcc r16-8740] libstdc++: Fix constraint recursion in std::indirect's operator== [PR124890]

Patrick Palka ppalka@gcc.gnu.org
Fri Apr 17 16:58:00 GMT 2026


https://gcc.gnu.org/g:35d754588329660ea297bca621747840bffbc7e5

commit r16-8740-g35d754588329660ea297bca621747840bffbc7e5
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Apr 17 11:19:58 2026 -0400

    libstdc++: Fix constraint recursion in std::indirect's operator== [PR124890]
    
    Like in r16-559 for std::expected, std::indirect's operator== is also
    prone to constraint recursion due to CWG 2369, for the Mandates that we
    implement as an associated constraint.  This patch works around the
    recursion in a similar manner as done for std::expected (and
    std::basic_const_iterator).
    
            PR libstdc++/124890
            PR libstdc++/119714
            PR libstdc++/112490
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/indirect.h (indirect::operator==): Replace
            non-dependent std::indirect function parameter with a
            dependent one of type indirect<_Vp> where _Vp matches _Tp.
            * testsuite/std/memory/indirect/124890.cc: New test.
    
    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>

Diff:
---
 libstdc++-v3/include/bits/indirect.h                 | 4 ++--
 libstdc++-v3/testsuite/std/memory/indirect/124890.cc | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/indirect.h b/libstdc++-v3/include/bits/indirect.h
index 2df46cc39a21..6490a77a5079 100644
--- a/libstdc++-v3/include/bits/indirect.h
+++ b/libstdc++-v3/include/bits/indirect.h
@@ -344,11 +344,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return __lhs.__get() == __rhs.__get();
 	}
 
-      template<typename _Up>
+      template<typename _Up, same_as<_Tp> _Vp>
 	requires (!__is_indirect<_Up>) // See PR c++/99599
 	  && requires (const _Tp& __t, const _Up& __u) { __t == __u; }
 	friend constexpr bool
-	operator==(const indirect& __lhs, const _Up& __rhs)
+	operator==(const indirect<_Vp, _Alloc>& __lhs, const _Up& __rhs)
 	noexcept(noexcept(*__lhs == __rhs))
 	{
 	  if (!__lhs._M_objp)
diff --git a/libstdc++-v3/testsuite/std/memory/indirect/124890.cc b/libstdc++-v3/testsuite/std/memory/indirect/124890.cc
new file mode 100644
index 000000000000..ce44256f2244
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/memory/indirect/124890.cc
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++26 } }
+
+// PR libstdc++/124890 - Circular constraint in std::indirect::operator==
+
+#include <memory>
+#include <vector>
+
+using I = std::vector<std::indirect<int>>::iterator;
+static_assert(std::totally_ordered<I>);


More information about the Libstdc++-cvs mailing list