libstdc++: Add lightweight replacement for std::numeric_limits (PR 92546)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 17 Feb 2020 14:30:02 +0000 (14:30 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 17 Feb 2020 15:11:04 +0000 (15:11 +0000)
commitc03b53da9129ae2d5ac9629c4b874d0981a7d418
treec93017e5e0b7094038b5b8d282aa3e243e557f07
parent4540ef781bcefffe779a8b31950ea737733f06a4
libstdc++: Add lightweight replacement for std::numeric_limits (PR 92546)

Many uses of std::numeric_limits in C++17 and C++20 features only really
need the min(), max() and digits constants for integral types. By adding
__detail::__int_limits we can avoid including the whole <limits> header.

The <limits> header isn't especially large, but avoiding it still gives
small savings in compilation time and memory usage for the compiler.

There are also C++11 features that could benefit from this change (e.g.
<bits/hashtable_policy.h> and <bits/uniform_int_dist.h>) but I won't
change those until stage 1.

The implementation of __int_limits assumes two's complement integers,
which is true for all targets supported by GCC.

PR libstdc++/92546 (partial)
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/int_limits.h: New header.
* include/bits/parse_numbers.h (__select_int::_Select_int): Replace
numeric_limits with __detail::__int_limits.
* include/std/bit (__rotl, __rotr, __countl_zero, __countl_one)
(__countr_zero, __countr_one, __popcount, __ceil2, __floor2, __log2p1):
Likewise.
* include/std/charconv (__to_chars_8, __from_chars_binary)
(__from_chars_alpha_to_num, from_chars): Likewise.
* include/std/memory_resource (polymorphic_allocator::allocate)
(polymorphic_allocator::allocate_object): Likewise.
* include/std/string_view (basic_string_view::_S_compare): Likewise.
* include/std/utility (in_range): Likewise.
* testsuite/20_util/integer_comparisons/in_range_neg.cc: Adjust for
extra error about incomplete type __int_limits<bool>.
* testsuite/26_numerics/bit/bit.count/countl_one.cc: Include <limits>.
* testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise.
* testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Likewise.
* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Likewise.
* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.
* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
23 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/int_limits.h [new file with mode: 0644]
libstdc++-v3/include/bits/parse_numbers.h
libstdc++-v3/include/std/bit
libstdc++-v3/include/std/charconv
libstdc++-v3/include/std/memory_resource
libstdc++-v3/include/std/string_view
libstdc++-v3/include/std/utility
libstdc++-v3/testsuite/20_util/integer_comparisons/in_range_neg.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_one.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.count/countl_zero.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_one.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.count/countr_zero.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.count/popcount.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/floor2.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ispow2.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/log2p1.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotl.cc
libstdc++-v3/testsuite/26_numerics/bit/bit.rotate/rotr.cc