libstdc++: Use hidden friends for vector<bool>::reference swap overloads
authorJonathan Wakely <jwakely@redhat.com>
Thu, 11 Nov 2021 20:51:15 +0000 (20:51 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 16 Nov 2021 16:42:59 +0000 (16:42 +0000)
These swap overloads are non-standard, but are needed to make swap work
for vector<bool>::reference rvalues. They don't need to be called
explicitly, only via ADL, so hide them from normal lookup. This is what
I've proposed as the resolution to LWG 3638.

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (swap(_Bit_reference, _Bit_reference))
(swap(_Bit_reference, bool&), swap(bool&, _Bit_reference)):
Define as hidden friends of _Bit_reference.

libstdc++-v3/include/bits/stl_bvector.h

index 381c47b..6807068 100644 (file)
@@ -125,36 +125,36 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     void
     flip() _GLIBCXX_NOEXCEPT
     { *_M_p ^= _M_mask; }
-  };
 
 #if __cplusplus >= 201103L
-  _GLIBCXX20_CONSTEXPR
-  inline void
-  swap(_Bit_reference __x, _Bit_reference __y) noexcept
-  {
-    bool __tmp = __x;
-    __x = __y;
-    __y = __tmp;
-  }
+    _GLIBCXX20_CONSTEXPR
+    friend void
+    swap(_Bit_reference __x, _Bit_reference __y) noexcept
+    {
+      bool __tmp = __x;
+      __x = __y;
+      __y = __tmp;
+    }
 
-  _GLIBCXX20_CONSTEXPR
-  inline void
-  swap(_Bit_reference __x, bool& __y) noexcept
-  {
-    bool __tmp = __x;
-    __x = __y;
-    __y = __tmp;
-  }
+    _GLIBCXX20_CONSTEXPR
+    friend void
+    swap(_Bit_reference __x, bool& __y) noexcept
+    {
+      bool __tmp = __x;
+      __x = __y;
+      __y = __tmp;
+    }
 
-  _GLIBCXX20_CONSTEXPR
-  inline void
-  swap(bool& __x, _Bit_reference __y) noexcept
-  {
-    bool __tmp = __x;
-    __x = __y;
-    __y = __tmp;
-  }
+    _GLIBCXX20_CONSTEXPR
+    friend void
+    swap(bool& __x, _Bit_reference __y) noexcept
+    {
+      bool __tmp = __x;
+      __x = __y;
+      __y = __tmp;
+    }
 #endif
+  };
 
   struct _Bit_iterator_base
   : public std::iterator<std::random_access_iterator_tag, bool>