[Bug libstdc++/84580] Equality and relational ops for containers behave differently in Debug Mode

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Feb 27 10:14:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84580

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-02-27
     Ever confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This change would meet the standard's requirement that a != b is equivalent to
!(a == b)

--- a/libstdc++-v3/include/debug/vector
+++ b/libstdc++-v3/include/debug/vector
@@ -725,7 +725,7 @@ namespace __debug
     inline bool
     operator!=(const vector<_Tp, _Alloc>& __lhs,
               const vector<_Tp, _Alloc>& __rhs)
-    { return __lhs._M_base() != __rhs._M_base(); }
+    { return !(__lhs == __rhs); }

   template<typename _Tp, typename _Alloc>
     inline bool



It would change the behaviour for this program:

#include <debug/vector>
#include <cassert>

struct foo { };

bool operator!=(std::vector<foo*> const& v1, std::vector<foo*> const& v2)
{ return &v1 != &v2; }

int main()
{
  __gnu_debug::vector<foo*> v1, v2;
  assert(v1 != v2);
}

Currently the operator!= for debug vectors calls the program-defined overload
for std::vectors, but with the patch above it would call operator== for debug
vectors which calls the standard operator== for std::vectors. This is probably
OK, the program above is pathologically contrived, and meeting the standard
requirements when _GLIBCXX_DEBUG is defined is more important, so that
_GLIBCXX_DEBUG doesn't change semantics.


More information about the Gcc-bugs mailing list