This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/60519] Debug mode should check comparators for irreflexivity


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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to FranÃois Dumont from comment #2)
> So yes it doubles the number of comparisons which is definitely a

Well actually your patch doesn't double the number, because you only do the
reverse check when the first check returns true.

> performance hint but your patch on the other hand expect to detect an
> implementation issue on only 1 use case so it can miss many kind of wrong
> implementation on special instances.

The most common mistake I want this to detect is simply trying to define
something equivalent to operator<= instead of operator< (see PR 59391 that I
linked to) and that will be detected for every value, so you only need to check
the first one. i.e. I want to check for irreflexivity.

Your patch checks for antisymmetry instead, which is also required for a strict
weak order, but is a different property.

Checking for antisymmetry is necessary to check broken orders like this:

bool cmp(const pair<int,int>& l, const pair<int,int>& r)
{ return l.first < r.first || l.second < r.second; }


Your patch also only works for C++11, but there's no reason this shouldn't work
for C++03 too. Which algorithms benefit from handling heterogeneous types in
these checks?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]