Skip to content

std::numeric_limits<bool>::traps should be true #166053

@Alcaro

Description

@Alcaro
#include <limits>

bool bool_trap() { return std::numeric_limits<bool>::traps; }
bool char_trap() { return std::numeric_limits<char>::traps; }
bool int_trap() { return std::numeric_limits<int>::traps; }

Result: false, true, true https://godbolt.org/z/q94jhqjsT

Expected: true, true, true. true/false traps just as much as 1/0 (if not optimized out - it is UB).

You can argue that division by false promotes to int, therefore it's not an operation on bool that traps, but if so, char is wrong.

Alternatively, one can argue that the entire traps member should be deprecated and removed, since every trapping operation is UB, and reasoning about the behavior of undefined behavior makes no sense.

See also microsoft/STL#5816, where MS-STL asks what traps should do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions