[Bug c++/78420] New: std::less<T*> is not an total order with optimization enabled
tomaszkam at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Nov 18 13:11:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420
Bug ID: 78420
Summary: std::less<T*> is not an total order with optimization
enabled
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tomaszkam at gmail dot com
Target Milestone: ---
The 20.14.6 [comparisons] p14:
For templates greater, less, greater_equal, and less_equal, the specializations
for any pointer type yield a total order, even if the built-in operators <, >,
<=
, >= do not.
Requires that the less<T*> is an total order, which means that the one of the
following is true for every pair of pointer values a,b:
1) lt(a, b)
2) lt(b, a)
3) !lt(a,b) && !lt(b, a) //i.e. a == b, where equality is generated from lessw
where lt is object on less<T*>.
This does not hold for following code snippet when compared with O2:
#include <iostream>
int b[8];
int a[8];
int main()
{
auto p = a + 8;
std::less<int*> lt;
std::cout << p << ' ' << b
<< ' ' << lt(p, b)
<< ' ' << lt(b, p)
<< ' ' << (!lt(p, b) && !lt(b, p)) << std::endl;
}
The output is: 0x6015c0 0x6015c0 0 0 0
(link to live example, require optimization to be enabled:
http://melpon.org/wandbox/permlink/vyY82MsxrxWNyOOJ#).
More information about the Gcc-bugs
mailing list