[gcc(refs/users/aoliva/heads/testme)] libstdc++: follow std in numeric_limits<bool>::traps and integral traps
Alexandre Oliva
aoliva@gcc.gnu.org
Sat Apr 18 08:41:24 GMT 2026
https://gcc.gnu.org/g:8d31b2534874be7223ac887ccd3f9c79d5963f50
commit 8d31b2534874be7223ac887ccd3f9c79d5963f50
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Apr 16 01:06:08 2026 -0300
libstdc++: follow std in numeric_limits<bool>::traps and integral traps
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.
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.
Diff:
---
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 57e4cbbe0136..36d6ab25bdb9 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 f4248e0f602a..59a9b9209872 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 f0ba2851a0a2..cb775fbd438e 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;
More information about the Libstdc++-cvs
mailing list