From e8439c1c9ddc02e8f3aa9726cd765637b34d68fb Mon Sep 17 00:00:00 2001 From: smikims Date: Tue, 25 Jan 2022 06:07:40 -0800 Subject: [PATCH] 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. --- source/util/small_vector.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/util/small_vector.h b/source/util/small_vector.h index f2c1147b..8f56268a 100644 --- a/source/util/small_vector.h +++ b/source/util/small_vector.h @@ -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& lhs, const SmallVector& rhs) { return rhs == lhs; } +#endif friend bool operator!=(const SmallVector& lhs, const std::vector& rhs) { return !(lhs == rhs);