Skip to content

Conversation

@vedranmiletic
Copy link
Contributor

@vedranmiletic vedranmiletic commented Nov 27, 2025

Building LLVM with CMAKE_CXX_STANDARD set to 20 fails since the iterator facade is not fully compatible with C++20. To make it compatible, specific operator overloads have to be constrained.

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

Patch by Jonathan Wakely.

Fixes #139072.

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

Patch by Jonathan Wakely.

Fixes llvm#139072.
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2025

@llvm/pr-subscribers-llvm-adt

Author: Vedran Miletić (vedranmiletic)

Changes

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

Patch by Jonathan Wakely.

Fixes #139072.


Full diff: https://github.com/llvm/llvm-project/pull/169772.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/iterator.h (+5-1)
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.");

Copy link
Contributor

@jwakely jwakely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted at #139072 (comment) there are other operators which should really be constrained similarly. So this fixes the immediate issue, but there are still latent bugs that might cause similar errors later.

@jwakely
Copy link
Contributor

jwakely commented Nov 27, 2025

but there are still latent bugs that might cause similar errors later.

But they could be fixed later, if needed.

@cor3ntin
Copy link
Contributor

Please update the description of the PR with a description of the problem you are trying to fix, I had to find this comment to understand the context. Thanks
#139072 (comment)

Co-authored-by: A. Jiang <de34@live.cn>
@github-actions
Copy link

github-actions bot commented Nov 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@vedranmiletic
Copy link
Contributor Author

Please update the description of the PR with a description of the problem you are trying to fix, I had to find this comment to understand the context. Thanks #139072 (comment)

Hope it is better now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building LLVM 20.1.4 fails with C++20

5 participants