https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118134
Bug ID: 118134 Summary: std::bit_cast handling of bool anad padding bits is inconsistent at compile time vs runtime Product: gcc Version: 14.2.0 Status: UNCONFIRMED Keywords: accepts-invalid, wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` #include <bit> constexpr auto c = (char)('A'&~0x1); constexpr bool A = std::bit_cast<bool>(c); static_assert(!A); bool t = A; int main() { char c1 = c; bool t1 = std::bit_cast<bool>(c1); __builtin_printf("%s\n", A ? "true" : "false"); __builtin_printf("%s\n", t ? "true" : "false"); __builtin_printf("%s\n", t1 ? "true" : "false"); } ``` GCC accepts the above even though the bool representation is only 0x01/0x00 are valid as far as I know. So at constexpr time, GCC thinks bool has padding bits. While runtime we get a different answer, true.