GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

Libstdc++: Follow the standard for numeric_limits<bool>::traps

Libstdc++ now correctly sets `numeric_limits<bool>::traps` to `false`, aligning with the C++ standard.

This commit aligns numeric_limits<bool>::traps in libstdc++ with the C++ standard, setting it to false. The previous interpretation incorrectly assumed that traps referred to operations that might trap (like division by zero) on integral types, leading to unintended behavior with the __glibcxx_integral_traps setting. This change defaults __glibcxx_integral_traps to false and removes overrides based on the flawed interpretation. While the __glibcxx_integral_traps option is retained for ABI compatibility and potential future use, the default behavior now aligns more closely with the standard, reducing unexpected trapping behavior.

In Details

std::numeric_limits provides information about built-in types at compile time. The traps member indicates whether certain values of a type can cause traps (hardware exceptions). Historically, there was ambiguity around numeric_limits<bool>::traps and whether it applied to trapping *values* or trapping *operations*. This commit resolves this ambiguity in favor of the former, aligning libstdc++ with the standard. Relevant files include <limits> and various cpu_defines.h in the config/cpu directory. This area is subtle and can affect exception handling and program behavior.

For Context

std::numeric_limits is a C++ template that provides information about the properties of numeric types, such as the minimum and maximum representable values, precision, and whether certain operations might result in traps (hardware exceptions). The traps member of numeric_limits indicates whether using specific values of a type (like bool) might cause a hardware trap. This commit corrects an interpretation in libstdc++ related to numeric_limits<bool>::traps, ensuring it aligns with the C++ standard. This ensures that programs behave as expected regarding potential hardware exceptions, improving portability and predictability.

Filed Under: libstdc++numeric_limitsbooltrapsstandard compliance