]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: follow std in numeric_limits<bool>::traps and integral traps
authorAlexandre Oliva <oliva@adacore.com>
Wed, 29 Apr 2026 01:31:23 +0000 (22:31 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Wed, 29 Apr 2026 01:31:23 +0000 (22:31 -0300)
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 [deleted file]
libstdc++-v3/config/cpu/powerpc/cpu_defines.h [deleted file]
libstdc++-v3/configure.host
libstdc++-v3/include/std/limits

diff --git a/libstdc++-v3/config/cpu/arm/cpu_defines.h b/libstdc++-v3/config/cpu/arm/cpu_defines.h
deleted file mode 100644 (file)
index 57e4cbb..0000000
+++ /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 (file)
index f4248e0..0000000
+++ /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
index ff97216167decaccd18605e238309906008f5cf0..e52a32bb4c682c03a78b5a1c4e6a619a22028f5a 100644 (file)
@@ -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
 
 
index f0ba2851a0a2e9087eb9fd9dc65f1cc4995b3b20..cfdbe02c844c2f1f5ea9575ae1e112352f5b0c3f 100644 (file)
 // 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