[PATCH] libstdc++: Members missing in std::numeric_limits<integer-class type>

Jonathan Wakely jwakely@redhat.com
Wed Jul 2 09:49:26 GMT 2025


On 02/07/25 03:36 +0300, Mateusz Zych wrote:
>Hello libstdc++ Team!
>
>I have recently found a bug in libstdc++, that is,
>the std::numeric_limits<> template specializations for integer-class types
>are missing some of static data members,
>which results in compilation errors of valid C++ code:
>
>   - Compiler Explorer: https://godbolt.org/z/E7z4WYfj4
>
>Since adding missing member constants, which are the most relevant to
>integer-like types,
>was not a lot of code, I have prepared a Git patch with relevant changes.
>
>I hope this patch is useful, Mateusz Zych

Thanks, I don't think there was any reason to omit these members, and I
agree we should add them.

The patch is simple and obvious enough that I don't think we need a
copyright assignment or DCO sign-off, so I'll push this to the
relevant branches. Thanks!


>From 1e83287bbd6adf6ad8f483bd2f891692e0bed0c7 Mon Sep 17 00:00:00 2001
>From: Mateusz Zych <mte.zych@gmail.com>
>Date: Wed, 2 Jul 2025 01:51:40 +0300
>Subject: [PATCH] libstdc++: Added missing member constants to numeric_limits
> specializations for integer-class types.
>
>25.3.4.4 Concept weakly_incrementable      [iterator.concept.winc]
>
>  (5) For every integer-class type I,
>      let B(I) be a unique hypothetical extended integer type
>      of the same signedness with the same width as I.
>
>      [Note 2: The corresponding
>               hypothetical specialization numeric_limits<B(I)>
>               meets the requirements on
>               numeric_limits specializations for integral types.]
>
> (11) For every (possibly cv-qualified) integer-class type I,
>      numeric_limits<I> is specialized such that:
>
>      - each static data member m
>        has the same value as numeric_limits<B(I)>::m, and
>
>      - each static member function f
>        returns I(numeric_limits<B(I)>::f()).
>
>libstdc++-v3/ChangeLog:
>
>	* include/bits/max_size_type.h
>	(numeric_limits<__max_size_type>): New static data members.
>	(numeric_limits<__max_diff_type>): Likewise.
>---
> libstdc++-v3/include/bits/max_size_type.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h
>index 73a6d141d5b..bc7700506a2 100644
>--- a/libstdc++-v3/include/bits/max_size_type.h
>+++ b/libstdc++-v3/include/bits/max_size_type.h
>@@ -775,6 +775,9 @@ namespace ranges
>       static constexpr bool is_signed = false;
>       static constexpr bool is_integer = true;
>       static constexpr bool is_exact = true;
>+      static constexpr bool is_bounded = true;
>+      static constexpr bool is_modulo = true;
>+      static constexpr bool radix = 2;
>       static constexpr int digits
> 	= __gnu_cxx::__int_traits<_Sp::__rep>::__digits + 1;
>       static constexpr int digits10
>@@ -802,6 +805,9 @@ namespace ranges
>       static constexpr bool is_signed = true;
>       static constexpr bool is_integer = true;
>       static constexpr bool is_exact = true;
>+      static constexpr bool is_bounded = true;
>+      static constexpr bool is_modulo = false;
>+      static constexpr bool radix = 2;
>       static constexpr int digits = numeric_limits<_Sp>::digits - 1;
>       static constexpr int digits10
> 	= static_cast<int>(digits * numbers::ln2 / numbers::ln10);
>-- 
>2.48.1
>



More information about the Libstdc++ mailing list