[PATCH v2] libstdc++: follow std in numeric_limits<bool>::traps and integral traps
Jonathan Wakely
jwakely@redhat.com
Wed Apr 22 09:23:02 GMT 2026
On Wed, 22 Apr 2026 at 07:12, Alexandre Oliva <oliva@adacore.com> wrote:
>
> On Apr 21, 2026, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> > This is strictly speaking an ABI change for most targets, but I doubt
> > anybody cares about numeric_limits<integral-type>::traps. I hope
> > nobody is depending on it for anything.
>
> > Anybody who needs the old behaviour can compile with
> > -D__glibcxx_integral_traps=1 if they really need it, so I think this
> > is OK to fix ion stage 1.
>
> Given the ABI change argument, I decided to revert the bool
> specialization to use the macro, so that -D__glibcxx_integral_traps=1
> fully restores the earlier ABI properties.
>
> >> (should the otherwise-effectively-empty cpu_defines.h headers be deleted
> >> altogether?)
>
> > I had to look into that, but it looks like we don't bother having an
> > empty cpu_defines.h, and just use the default generic/cpu_defines.h
> > file. So I think yes, they should be removed.
>
> ACK
>
> > I don't think we need such a detailed comment here (especially not
> > referring to non-bool specializations).
>
> > We already have this comment above the whole explicit specialization,
> > which justifies why it's there and what all its values are:
>
> > // _GLIBCXX_RESOLVE_LIB_DEFECTS
> > // 184. numeric_limits<bool> wording problems
>
> > So I would just remove the comment on traps entirely.
>
> Fair enough. I tweaked the opening comment, and dropped the one next to
> the specialization. Here's what I've just regstrapped on
> x86_64-linux-gnu and powerpc64le-linux-gnu. Ok for stage1?
OK for stage 1 - thanks!
>
>
> 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, presumably in response to
> issue 184.
>
> Issue 554 clarifies that traps is about values that may trap, rather
> than operations that may trap, so we were wrong in the interpretation
> about divide-by-zero operations' trapping on integral types that led
> to __glibcxx_integral_traps's defaulting to true, and some of its
> overrides.
>
> Align numeric_limits<bool>::traps with the standard, default
> __glibcxx_integral_traps to false, drop the overriders based on the
> incorrect interpretation, but keep __glibcxx_integral_traps to allow
> command-line restoring of this ABI fix, and for the admittedly
> unlikely case of trapping integral values' coming to exist on some
> architecture.
>
>
> for libstdc++-v3/ChangeLog
>
> * include/std/limits (__glibcxx_integral_traps): Set to
> false. Update comments.
> (numeric_limits<bool>::traps): Drop comments.
> * config/cpu/arm/cpu_defines.h: Remove.
> * config/cpu/powerpc/cpu_defines.h: Likewise.
> * configure.host (cpu_defines_dir): Adjust.
> ---
> libstdc++-v3/config/cpu/arm/cpu_defines.h | 40 -------------------------
> libstdc++-v3/config/cpu/powerpc/cpu_defines.h | 36 -----------------------
> libstdc++-v3/configure.host | 6 ----
> libstdc++-v3/include/std/limits | 14 +++++----
> 4 files changed, 8 insertions(+), 88 deletions(-)
> delete mode 100644 libstdc++-v3/config/cpu/arm/cpu_defines.h
> delete mode 100644 libstdc++-v3/config/cpu/powerpc/cpu_defines.h
>
> diff --git a/libstdc++-v3/config/cpu/arm/cpu_defines.h b/libstdc++-v3/config/cpu/arm/cpu_defines.h
> deleted file mode 100644
> index 57e4cbbe0136b..0000000000000
> --- a/libstdc++-v3/config/cpu/arm/cpu_defines.h
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -// Specific definitions for generic platforms -*- C++ -*-
> -
> -// Copyright (C) 2015-2026 Free Software Foundation, Inc.
> -//
> -// This file is part of the GNU ISO C++ Library. This library is free
> -// software; you can redistribute it and/or modify it under the
> -// terms of the GNU General Public License as published by the
> -// Free Software Foundation; either version 3, or (at your option)
> -// any later version.
> -
> -// This library is distributed in the hope that it will be useful,
> -// but WITHOUT ANY WARRANTY; without even the implied warranty of
> -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -// GNU General Public License for more details.
> -
> -// Under Section 7 of GPL version 3, you are granted additional
> -// permissions described in the GCC Runtime Library Exception, version
> -// 3.1, as published by the Free Software Foundation.
> -
> -// You should have received a copy of the GNU General Public License and
> -// a copy of the GCC Runtime Library Exception along with this program;
> -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
> -// <http://www.gnu.org/licenses/>.
> -
> -/** @file bits/cpu_defines.h
> - * This is an internal header file, included by other library headers.
> - * Do not attempt to use it directly. @headername{iosfwd}
> - */
> -
> -#ifndef _GLIBCXX_CPU_DEFINES
> -#define _GLIBCXX_CPU_DEFINES 1
> -
> -// Integer divide instructions don't trap on ARM.
> -#ifdef __ARM_ARCH_EXT_IDIV__
> -#define __glibcxx_integral_traps false
> -#else
> -#define __glibcxx_integral_traps true
> -#endif
> -
> -#endif
> diff --git a/libstdc++-v3/config/cpu/powerpc/cpu_defines.h b/libstdc++-v3/config/cpu/powerpc/cpu_defines.h
> deleted file mode 100644
> index f4248e0f602a3..0000000000000
> --- a/libstdc++-v3/config/cpu/powerpc/cpu_defines.h
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -// Specific definitions for generic platforms -*- C++ -*-
> -
> -// Copyright (C) 2005-2026 Free Software Foundation, Inc.
> -//
> -// This file is part of the GNU ISO C++ Library. This library is free
> -// software; you can redistribute it and/or modify it under the
> -// terms of the GNU General Public License as published by the
> -// Free Software Foundation; either version 3, or (at your option)
> -// any later version.
> -
> -// This library is distributed in the hope that it will be useful,
> -// but WITHOUT ANY WARRANTY; without even the implied warranty of
> -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -// GNU General Public License for more details.
> -
> -// Under Section 7 of GPL version 3, you are granted additional
> -// permissions described in the GCC Runtime Library Exception, version
> -// 3.1, as published by the Free Software Foundation.
> -
> -// You should have received a copy of the GNU General Public License and
> -// a copy of the GCC Runtime Library Exception along with this program;
> -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
> -// <http://www.gnu.org/licenses/>.
> -
> -/** @file bits/cpu_defines.h
> - * This is an internal header file, included by other library headers.
> - * Do not attempt to use it directly. @headername{iosfwd}
> - */
> -
> -#ifndef _GLIBCXX_CPU_DEFINES
> -#define _GLIBCXX_CPU_DEFINES 1
> -
> -// Integer divide instructions don't trap on PowerPC.
> -#define __glibcxx_integral_traps false
> -
> -#endif
> diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
> index ff97216167dec..e52a32bb4c682 100644
> --- a/libstdc++-v3/configure.host
> +++ b/libstdc++-v3/configure.host
> @@ -150,15 +150,9 @@ case "${host_cpu}" in
> amdgcn)
> cpu_defines_dir=cpu/gcn
> ;;
> - arm*)
> - cpu_defines_dir=cpu/arm
> - ;;
> nvptx)
> cpu_defines_dir=cpu/nvptx
> ;;
> - powerpc* | rs6000)
> - cpu_defines_dir=cpu/powerpc
> - ;;
> esac
>
>
> diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits
> index f0ba2851a0a2e..cfdbe02c844c2 100644
> --- a/libstdc++-v3/include/std/limits
> +++ b/libstdc++-v3/include/std/limits
> @@ -81,10 +81,15 @@
> // The default values are appropriate for many 32-bit targets.
>
> // 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.
> +// integral exceptional values is division by zero, but that's an operation,
> +// not a value, and traps is about values that trap (Issue554), so there aren't
> +// any for integral types. The standard has numeric_limits<bool>::traps
> +// explicitly set to false. However, we used to set them all to true based on
> +// the division-by-zero misinterpretation, so we retain this macro, and those
> +// who relied on the misinterpretation can restore it with a command-line
> +// define and revert the ABI-changing effects of this fix.
> #ifndef __glibcxx_integral_traps
> -# define __glibcxx_integral_traps true
> +# define __glibcxx_integral_traps false
> #endif
>
> // float
> @@ -446,9 +451,6 @@ _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 tinyness_before = false;
> static _GLIBCXX_USE_CONSTEXPR float_round_style round_style
>
> --
> 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