[llvm] Fixed build with C++20 standard (PR #169772)
Vedran Miletić via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 4 08:13:08 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/4] 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/4] 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.");
>From d3785dd740884b20159cb9b0c047fb96ab7bf9a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vedran=20Mileti=C4=87?= <vedran at miletic.net>
Date: Fri, 28 Nov 2025 08:56:14 +0100
Subject: [PATCH 3/4] Format
---
llvm/include/llvm/ADT/iterator.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h
index f9f808f09e3b7..f37ff1c3a1c9e 100644
--- a/llvm/include/llvm/ADT/iterator.h
+++ b/llvm/include/llvm/ADT/iterator.h
@@ -267,7 +267,8 @@ class iterator_adaptor_base
return *static_cast<DerivedT *>(this);
}
using BaseT::operator-;
- template <bool Enabled = bool(BaseT::IsRandomAccess), std::enable_if_t<Enabled, int> = 0>
+ template <bool Enabled = bool(BaseT::IsRandomAccess),
+ std::enable_if_t<Enabled, int> = 0>
difference_type operator-(const DerivedT &RHS) const {
static_assert(
BaseT::IsRandomAccess,
>From 807d18afa434d8ad8764b9411a04248b3031ef9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vedran=20Mileti=C4=87?= <vedran at miletic.net>
Date: Mon, 1 Dec 2025 17:27:36 +0100
Subject: [PATCH 4/4] Update llvm/include/llvm/ADT/iterator.h
Co-authored-by: Jakub Kuderski <kubakuderski at gmail.com>
---
llvm/include/llvm/ADT/iterator.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h
index f37ff1c3a1c9e..c0495e24893fb 100644
--- a/llvm/include/llvm/ADT/iterator.h
+++ b/llvm/include/llvm/ADT/iterator.h
@@ -267,8 +267,8 @@ class iterator_adaptor_base
return *static_cast<DerivedT *>(this);
}
using BaseT::operator-;
- template <bool Enabled = bool(BaseT::IsRandomAccess),
- std::enable_if_t<Enabled, int> = 0>
+ template <bool Enabled = BaseT::IsRandomAccess,
+ typename = std::enable_if_t<Enabled>>
difference_type operator-(const DerivedT &RHS) const {
static_assert(
BaseT::IsRandomAccess,
More information about the llvm-commits
mailing list