From eb829c6789c5aebacc8b96b23d220667fa548d50 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Tue, 28 Apr 2026 22:31:23 -0300 Subject: [PATCH] libstdc++: follow std in numeric_limits::traps and integral traps There's a comment from 2002 suggesting that numeric_limits::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::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::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 57e4cbbe013..00000000000 --- 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 -// . - -/** @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 f4248e0f602..00000000000 --- 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 -// . - -/** @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 ff97216167d..e52a32bb4c6 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 f0ba2851a0a..cfdbe02c844 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::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