]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
xlist: use friend instead of member operators
authorCasey Bodley <cbodley@redhat.com>
Fri, 11 Feb 2022 23:56:30 +0000 (18:56 -0500)
committerKefu Chai <tchaikov@gmail.com>
Thu, 17 Mar 2022 14:00:35 +0000 (22:00 +0800)
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<Dentry *>::const_iterat
or' and 'xlist<Dentry *>::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 <cbodley@redhat.com>
src/include/xlist.h

index 3c04312c714a4b5f3e839c6b76002183b652390c..7b482f70697ff1e13f9d6ab0893bbaff9a99a770 100644 (file)
@@ -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;
     }
   };