From: Casey Bodley Date: Fri, 11 Feb 2022 23:56:30 +0000 (-0500) Subject: xlist: use friend instead of member operators X-Git-Tag: v18.0.0~1237^2~10 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0b22b85817223cdfee6a6ab42f2ff27752fa05df;p=ceph-ci.git xlist: use friend instead of member operators resolves a c++20 compilation error with clang 13: In file included from ceph/src/client/Client.cc:55: In file included from ceph/src/messages/MClientCaps.h:19: In file included from ceph/src/mds/mdstypes.h:22: ceph/src/include/xlist.h:212:27: warning: ISO C++20 considers use of overloaded operator '!=' (with operand types 'xlist::const_iterat or' and 'xlist::const_iterator') to be ambiguous despite there being a unique best viable function with non-reversed arguments [-Wambiguous-reversed -operator] for (const auto &item : list) { ^ ceph/src/client/Client.cc:3299:63: note: in instantiation of member function 'operator<<' requested here ldout(cct, 20) << "link inode " << in << " parents now " << in->dentries << dendl; ^ ceph/src/include/xlist.h:202:10: note: candidate function with non-reversed arguments bool operator!=(const_iterator& rhs) const { ^ ceph/src/include/xlist.h:199:10: note: ambiguous candidate function with reversed arguments bool operator==(const_iterator& rhs) const { ^ Signed-off-by: Casey Bodley --- diff --git a/src/include/xlist.h b/src/include/xlist.h index 3c04312c714..7b482f70697 100644 --- a/src/include/xlist.h +++ b/src/include/xlist.h @@ -177,11 +177,11 @@ public: return *this; } bool end() const { return cur == 0; } - bool operator==(const iterator& rhs) const { - return cur == rhs.cur; + friend bool operator==(const iterator& lhs, const iterator& rhs) { + return lhs.cur == rhs.cur; } - bool operator!=(const iterator& rhs) const { - return cur != rhs.cur; + friend bool operator!=(const iterator& lhs, const iterator& rhs) { + return lhs.cur != rhs.cur; } }; @@ -201,11 +201,13 @@ public: return *this; } bool end() const { return cur == 0; } - bool operator==(const_iterator& rhs) const { - return cur == rhs.cur; + friend bool operator==(const const_iterator& lhs, + const const_iterator& rhs) { + return lhs.cur == rhs.cur; } - bool operator!=(const_iterator& rhs) const { - return cur != rhs.cur; + friend bool operator!=(const const_iterator& lhs, + const const_iterator& rhs) { + return lhs.cur != rhs.cur; } };