This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/84580] New: Equality and relational ops for containers behave differently in Debug Mode
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 26 Feb 2018 23:55:23 +0000
- Subject: [Bug libstdc++/84580] New: Equality and relational ops for containers behave differently in Debug Mode
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84580
Bug ID: 84580
Summary: Equality and relational ops for containers behave
differently in Debug Mode
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
This passes in normal mode but fails the second assertion when compiled with
-D_GLIBCXX_DEBUG
#include <cassert>
#include <vector>
struct foo { };
typedef std::vector<foo*> vect;
bool operator==(const vect&, const vect&) { return true; }
int main() {
vect v1;
vect v2;
v1.push_back(nullptr);
assert(v1 == v2);
assert(!(v1 != v2));
}
The problem is that in Debug Mode (v1 != v2) doesn't call (v1 == v2) which
would use the custom ::operator== overload.
Instead it calls (v1.base() != v2.base()) which then calls operator==, but with
arguments of type std::__cxx1998::vector, and so won't use the ::operator==
overload.
I think we need to make std::__debug::operator!= use == so that ADL can find
the same overload as would be found in normal mode, and similarly for >, <= and
>= (from Table 77, Optional container operations).