From f0b484892ce6e09cf79c858460c96d3540dba1a8 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 12 Oct 2021 23:28:26 -0700 Subject: [PATCH] [wpiutil] Fix StringMap iterator equality check (#3629) This fixes the following warning. The member function operator== only works in C++17, and the friend operator== only works in C++20. ``` /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:1847:46: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'const typename json::object_t::iterator' (aka 'const StringMapIterator') and 'const typename json::object_t::iterator') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator] return (m_it.object_iterator == other.m_it.object_iterator); ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:1863:20: note: in instantiation of member function 'wpi::detail::iter_impl::operator==' requested here return not operator==(other); ^ /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:5008:20: note: in instantiation of member function 'wpi::detail::iter_impl::operator!=' requested here if (it != end()) ^ /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/json.h:5025:16: note: in instantiation of function template specialization 'wpi::json::value, 0>' requested here return value(key, std::string(default_value)); ^ /Users/runner/.gradle/caches/transforms-2/files-2.1/c671f5a5dff922b8870f4eb33f4c8e2a/wpiutil-cpp-2022.1.1-alpha-3-1-g4e3fd7d-headers/wpi/StringMap.h:442:8: note: ambiguity is between a regular call to this operator and a call with the argument order reversed bool operator==(const DerivedTy &RHS) const { return Ptr == RHS.Ptr; } ^ ``` --- wpiutil/src/main/native/include/wpi/StringMap.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wpiutil/src/main/native/include/wpi/StringMap.h b/wpiutil/src/main/native/include/wpi/StringMap.h index 0800efb020..dac2f20914 100644 --- a/wpiutil/src/main/native/include/wpi/StringMap.h +++ b/wpiutil/src/main/native/include/wpi/StringMap.h @@ -439,7 +439,13 @@ public: return static_cast(*this); } +#if __cplusplus < 202002L bool operator==(const DerivedTy &RHS) const { return Ptr == RHS.Ptr; } +#else + friend bool operator==(const DerivedTy &LHS, const DerivedTy &RHS) { + return LHS.Ptr == RHS.Ptr; + } +#endif DerivedTy &operator++() { // Preincrement ++Ptr;