[C++20 build failure, Clang 15] Fix ambiguous-reversed-operator warning (#1199)

Move to a friend nonmember functions taking both arguments by reference-to-const.

Closes #1199

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/upb/pull/1199 from phallot:fix/ambiguous-reversed-operator 4ef9f65e7539df330943a55e257b5f8a87a208ca
PiperOrigin-RevId: 542572888
pull/13171/head
Pierre Hallot 1 year ago committed by Copybara-Service
parent a93e43f7e8
commit edbbb1581b
  1. 20
      upb/reflection/def.hpp

@ -318,8 +318,14 @@ class MessageDefPtr {
FieldDefPtr operator*() {
return FieldDefPtr(upb_MessageDef_Field(m_, i_));
}
bool operator!=(const FieldIter& other) { return i_ != other.i_; }
bool operator==(const FieldIter& other) { return i_ == other.i_; }
friend bool operator==(FieldIter lhs, FieldIter rhs) {
return lhs.i_ == rhs.i_;
}
friend bool operator!=(FieldIter lhs, FieldIter rhs) {
return !(lhs == rhs);
}
private:
const upb_MessageDef* m_;
@ -344,8 +350,14 @@ class MessageDefPtr {
OneofDefPtr operator*() {
return OneofDefPtr(upb_MessageDef_Oneof(m_, i_));
}
bool operator!=(const OneofIter& other) { return i_ != other.i_; }
bool operator==(const OneofIter& other) { return i_ == other.i_; }
friend bool operator==(OneofIter lhs, OneofIter rhs) {
return lhs.i_ == rhs.i_;
}
friend bool operator!=(OneofIter lhs, OneofIter rhs) {
return !(lhs == rhs);
}
private:
const upb_MessageDef* m_;

Loading…
Cancel
Save