-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Fixed build with C++20 standard #169772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixed build with C++20 standard #169772
Conversation
Overload for operator- in ADT iterator is now constrained with concept BaseT::IsRandomAccess. Patch by Jonathan Wakely. Fixes llvm#139072.
|
@llvm/pr-subscribers-llvm-adt Author: Vedran Miletić (vedranmiletic) ChangesOverload 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:
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.");
|
jwakely
left a comment
There was a problem hiding this 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.
But they could be fixed later, if needed. |
|
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 |
Co-authored-by: A. Jiang <[email protected]>
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Hope it is better now. |
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.