[PATCH] libstdc++: follow std in numeric_limits<bool>::traps
Jonathan Wakely
jwakely@redhat.com
Mon Apr 13 09:25:39 GMT 2026
On Fri, 10 Apr 2026 at 13:02, Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> There's a comment from 2002 suggesting that
> numeric_limits<bool>::traps was in a DR, but C++ standards including
> 11, 17 and 23 explicitly set it to false. I suppose whatever DR that
> comment referred to must have long been resolved in favor of what's in
> these much newer releases of the standard. So align it with the
> standards, and drop the comment.
https://cplusplus.github.io/LWG/issue497 (opened by Martin in 2005)
only covers floating-point types.
The comment probably refers to
https://cplusplus.github.io/LWG/issue184 which added the
numeric_limits<bool> specialization.
In 2006 Howard opened https://cplusplus.github.io/LWG/issue554 to
question the meaning of numeric_limits<bool>::traps but that was
closed as Not A Defect. I think that resolution casts doubt on how we
define traps for all integral types. We use:
// GCC only intrinsically supports modulo integral types. The only remaining
// integral exceptional values is division by zero. Only targets that do not
// signal division by zero in some "hard to ignore" way should use false.
#ifndef __glibcxx_integral_traps
# define __glibcxx_integral_traps true
#endif
This seems to suggest that we make it true because division by zero
might trap, but the resolution of 554 says that's an incorrect
interpretation. GCC has no integer values that can trap. I think this
is the case even for integer types with padding like __int20, because
those types have no valid values that can trap when used. The padding
bits do not participate in the value.
So I think the correct fix is to just get rid of
__glibcxx_integral_traps and set numeric_limits::traps to false for
all integral types. But that's definitely stage 1 material.
>
> Regstrapped on x86_64-linux-gnu. Ok to install? Not a regression
> AFAICT; perhaps for stage1?
>
>
> for libstdc++-v3/ChangeLog
>
> * include/std/limits (numeric_limits<bool>::traps): Set to
> false.
> ---
> libstdc++-v3/include/std/limits | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits
> index f0ba2851a0a2e..c160503e0a826 100644
> --- a/libstdc++-v3/include/std/limits
> +++ b/libstdc++-v3/include/std/limits
> @@ -446,10 +446,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true;
> static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false;
>
> - // It is not clear what it means for a boolean type to trap.
> - // This is a DR on the LWG issue list. Here, I use integer
> - // promotion semantics.
> - static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps;
> + static _GLIBCXX_USE_CONSTEXPR bool traps = false;
> static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false;
> static _GLIBCXX_USE_CONSTEXPR float_round_style round_style
> = round_toward_zero;
>
> --
> Alexandre Oliva, happy hacker https://blog.lx.oliva.nom.br/
> Free Software Activist FSFLA co-founder GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity.
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive!
>
More information about the Libstdc++
mailing list