-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Inline operator== and operator!= #67958
Conversation
Avoid triggering -Wnon-template-friend.
@llvm/pr-subscribers-llvm-adt ChangesAvoid triggering -Wnon-template-friend on newer GCC. Full diff: https://github.com/llvm/llvm-project/pull/67958.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h
index 667bece6d718385..c96e0b20e2d33d7 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -209,36 +209,31 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
return PagePtr[ElementIdx % PageSize];
}
+ /// Equality operator.
friend bool operator==(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS);
+ MaterializedIterator const &RHS) {
+ assert(LHS.PV == RHS.PV);
+ // Make sure we are comparing either end iterators or iterators pointing
+ // to materialized elements.
+ // It should not be possible to build two iterators pointing to non
+ // materialized elements.
+ assert(LHS.ElementIdx == LHS.PV->Size ||
+ (LHS.ElementIdx < LHS.PV->Size &&
+ LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
+ assert(RHS.ElementIdx == RHS.PV->Size ||
+ (RHS.ElementIdx < RHS.PV->Size &&
+ RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
+ return LHS.ElementIdx == RHS.ElementIdx;
+ }
+
friend bool operator!=(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS);
+ MaterializedIterator const &RHS) {
+ return !(LHS == RHS);
+ }
[[nodiscard]] size_t getIndex() const { return ElementIdx; }
};
- /// Equality operator.
- friend bool operator==(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS) {
- assert(LHS.PV == RHS.PV);
- // Make sure we are comparing either end iterators or iterators pointing
- // to materialized elements.
- // It should not be possible to build two iterators pointing to non
- // materialized elements.
- assert(LHS.ElementIdx == LHS.PV->Size ||
- (LHS.ElementIdx < LHS.PV->Size &&
- LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
- assert(RHS.ElementIdx == RHS.PV->Size ||
- (RHS.ElementIdx < RHS.PV->Size &&
- RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
- return LHS.ElementIdx == RHS.ElementIdx;
- }
-
- friend bool operator!=(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS) {
- return !(LHS == RHS);
- }
-
/// Iterators over the materialized elements of the vector.
///
/// This includes all the elements belonging to allocated pages,
|
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.
If it does what it says on the tin, sounds good to me.
It does and it breaks windows builds. |
Hi, we also use gcc internally to build the compiler and were seeing the warnings you are trying to fix here, so I tried applying your fix on our repo and it seems to fail with gcc 9.4.0 as well for the same errors I'm seeing with my Windows build of your fix. Namely this error:
|
So it would seem we would have to make the template <...>
class PagedVector {
...
class MaterializedIterator;
friend bool operator==(const MaterializeIterator& lhs, const MaterializedIterator& rhs);
class MaterializedIterator {
friend bool operator==(const MaterializeIterator& lhs, const MaterializedIterator& rhs) {
...
}
};
}; |
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Using @zygoloid suggestion it works on GCC (including 9.4, as tested on godbolt), macOS XCode 15, now waiting for the CI to verify Windows. @kuhar my understanding of your suggestion still triggers the Side note: does anyone know how to get LLVM work in godbolt? Using the vspkg package does not work for me (missing includes from llvm/.*). |
I am waiting for Windows to finish to reformat the PR... |
Ping @kuhar @zygoloid @dwblaikie. This seems to work without warnings on all the compilers I managed to test (gcc 9.4.0 on godbolt, latest GCC on godbolt, macOS XCode 15, and of course the CI). Adapted from @zygoloid suggestion. |
Hi! Anything preventing pushing this now? |
I was wondering the same. I do not have write rights. |
If you got your patch approved and don't have commit rights, you need to say that so someone else can push it for you. :) |
@vgvassilev could you take care of this? |
Avoid triggering -Wnon-template-friend on newer GCC.