Avoid infinite recursion in comparison operators on SmallVector (#4681)

C++20 automatically adds reversed versions of operator overloads for
consideration; in this particular instance this results in infinite
recursion, which has now been pointed out elsewhere as a known issue
when migrating to C++20. Here we just disable one of the overloads in
C++20 mode and let the auto-reversing take care of it for us.
This commit is contained in:
smikims 2022-01-25 06:07:40 -08:00 committed by GitHub
parent 58d8b4e29c
commit e8439c1c9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,9 +175,12 @@ class SmallVector {
return true;
}
// Avoid infinite recursion from rewritten operators in C++20
#if __cplusplus <= 201703L
friend bool operator==(const std::vector<T>& lhs, const SmallVector& rhs) {
return rhs == lhs;
}
#endif
friend bool operator!=(const SmallVector& lhs, const std::vector<T>& rhs) {
return !(lhs == rhs);