On Apr 13, 2026, Jonathan Wakely <[email protected]> wrote:
> 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.
I couldn't get myself to pull the trigger :-) but I've tested this:
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 for the
admittedly unlikely case of trapping integral values' existing on some
architecture.
Regstrapped on x86_64-linux-gnu. Also tested on arm-eabi and
riscv32-elf. Ok for stage1?
(should the otherwise-effectively-empty cpu_defines.h headers be deleted
altogether?)
for libstdc++-v3/ChangeLog
* include/std/limits (__glibcxx_integral_traps): Set to
false. Update comments.
(numeric_limits<bool>::traps): Likewise. Likewise.
* config/cpu/arm/cpu_defines.h (__glibcxx_integral_traps):
Drop overrider.
* config/cpu/powerpc/cpu_defines.h (__glibcxx_integral_traps):
Likewise.
---
libstdc++-v3/config/cpu/arm/cpu_defines.h | 7 -------
libstdc++-v3/config/cpu/powerpc/cpu_defines.h | 3 ---
libstdc++-v3/include/std/limits | 16 +++++++++-------
3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/libstdc++-v3/config/cpu/arm/cpu_defines.h
b/libstdc++-v3/config/cpu/arm/cpu_defines.h
index 57e4cbbe0136b..36d6ab25bdb90 100644
--- a/libstdc++-v3/config/cpu/arm/cpu_defines.h
+++ b/libstdc++-v3/config/cpu/arm/cpu_defines.h
@@ -30,11 +30,4 @@
#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
index f4248e0f602a3..59a9b92098726 100644
--- a/libstdc++-v3/config/cpu/powerpc/cpu_defines.h
+++ b/libstdc++-v3/config/cpu/powerpc/cpu_defines.h
@@ -30,7 +30,4 @@
#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/include/std/limits b/libstdc++-v3/include/std/limits
index f0ba2851a0a2e..cb775fbd438e5 100644
--- a/libstdc++-v3/include/std/limits
+++ b/libstdc++-v3/include/std/limits
@@ -81,10 +81,11 @@
// 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.
#ifndef __glibcxx_integral_traps
-# define __glibcxx_integral_traps true
+# define __glibcxx_integral_traps false
#endif
// float
@@ -446,10 +447,11 @@ _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;
+ // The standard is explicit in that the bool specialization has it set to
+ // false, whereas other integral types, for which no explicit
+ // specialization is given in the standard, follow the general
+ // specification.
+ 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!