![]() The spaceship operator for std::array uses memcmp when the __is_byte<value_type> trait is true, but memcmp isn't usable in constexpr contexts. Also, memcmp should only be used for unsigned byte types, because it gives the wrong answer for signed chars with negative values. We can simply check std::is_constant_evaluated() so that we don't use memcmp during constant evaluation. To fix the problem of using memcmp for inappropriate types, this patch adds new __is_memcmp_ordered and __is_memcmp_ordered_with traits. These say whether using memcmp will give the right answer for ordering operations such as lexicographical_compare and three-way comparisons. The new traits can be used in several places, and can also be used to implement my suggestion in PR 93059 comment 37 to use memcmp for unsigned integers larger than one byte on big endian targets. libstdc++-v3/ChangeLog: PR libstdc++/96851 * include/bits/cpp_type_traits.h (__is_memcmp_ordered): New trait that says if memcmp can be used for ordering. (__is_memcmp_ordered_with): Likewise, for two types. * include/bits/deque.tcc (__lex_cmp_dit): Use new traits instead of __is_byte and __numeric_traits. (__lexicographical_compare_aux1): Likewise. * include/bits/ranges_algo.h (__lexicographical_compare_fn): Likewise. * include/bits/stl_algobase.h (__lexicographical_compare_aux1) (__is_byte_iter): Likewise. * include/std/array (operator<=>): Likewise. Only use memcmp when std::is_constant_evaluated() is false. * testsuite/23_containers/array/comparison_operators/96851.cc: New test. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. |
||
---|---|---|
.. | ||
config | ||
doc | ||
include | ||
libsupc++ | ||
po | ||
python | ||
scripts | ||
src | ||
testsuite | ||
acinclude.m4 | ||
aclocal.m4 | ||
ChangeLog | ||
ChangeLog-1998 | ||
ChangeLog-1999 | ||
ChangeLog-2000 | ||
ChangeLog-2001 | ||
ChangeLog-2002 | ||
ChangeLog-2003 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
config.h.in | ||
configure | ||
configure.ac | ||
configure.host | ||
crossconfig.m4 | ||
fragment.am | ||
linkage.m4 | ||
Makefile.am | ||
Makefile.in | ||
README |
file: libstdc++-v3/README New users may wish to point their web browsers to the file index.html in the 'doc/html' subdirectory. It contains brief building instructions and notes on how to configure the library in interesting ways.