[llvm] Fixed build with C++20 standard (PR #169772)

Vedran Miletić via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 27 11:56:16 PST 2025


https://github.com/vedranmiletic updated https://github.com/llvm/llvm-project/pull/169772

>From f3b449a831c114da2403c7dda783a38d3fa28c99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vedran=20Mileti=C4=87?= <vedran at miletic.net>
Date: Thu, 27 Nov 2025 08:52:53 +0100
Subject: [PATCH 1/2] Fixed build with C++20 standard

Overload for operator- in ADT iterator is now constrained with concept
BaseT::IsRandomAccess.

Patch by Jonathan Wakely.

Fixes #139072.
---
 llvm/include/llvm/ADT/iterator.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h
index 6f0c42fe08bec..f55f9d4a3e7f2 100644
--- a/llvm/include/llvm/ADT/iterator.h
+++ b/llvm/include/llvm/ADT/iterator.h
@@ -267,7 +267,11 @@ class iterator_adaptor_base
     return *static_cast<DerivedT *>(this);
   }
   using BaseT::operator-;
-  difference_type operator-(const DerivedT &RHS) const {
+  difference_type operator-(const DerivedT &RHS) const
+#ifdef __cpp_concepts
+    requires(bool(BaseT::IsRandomAccess))
+#endif
+  {
     static_assert(
         BaseT::IsRandomAccess,
         "The '-' operator is only defined for random access iterators.");

>From bda2870d1d4adc7121bca5d53640381b054b3fc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vedran=20Mileti=C4=87?= <vedran at miletic.net>
Date: Thu, 27 Nov 2025 20:56:09 +0100
Subject: [PATCH 2/2] Update llvm/include/llvm/ADT/iterator.h

Co-authored-by: A. Jiang <de34 at live.cn>
---
 llvm/include/llvm/ADT/iterator.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h
index f55f9d4a3e7f2..f9f808f09e3b7 100644
--- a/llvm/include/llvm/ADT/iterator.h
+++ b/llvm/include/llvm/ADT/iterator.h
@@ -267,11 +267,8 @@ class iterator_adaptor_base
     return *static_cast<DerivedT *>(this);
   }
   using BaseT::operator-;
-  difference_type operator-(const DerivedT &RHS) const
-#ifdef __cpp_concepts
-    requires(bool(BaseT::IsRandomAccess))
-#endif
-  {
+  template <bool Enabled = bool(BaseT::IsRandomAccess), std::enable_if_t<Enabled, int> = 0>
+  difference_type operator-(const DerivedT &RHS) const {
     static_assert(
         BaseT::IsRandomAccess,
         "The '-' operator is only defined for random access iterators.");



More information about the llvm-commits mailing list