https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118135
Bug ID: 118135 Summary: undefined std::bit_cast for bool is not detected Product: gcc Version: 14.2.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org Target Milestone: --- Take: ``` #include <bit> auto c = (char)('A'&~0x1); int main() { bool t1 = std::bit_cast<bool>(c); __builtin_printf("%s\n", t1 ? "true" : "false"); } ``` -fsanitize=undefined should detect an invalid value for bool but currently does not. If we do: ``` #include <bit> auto c = (char)('A'&~0x1); bool t; int main() { bool t1 = std::bit_cast<bool>(c); t = t1; __builtin_printf("%s\n", t ? "true" : "false"); } ``` Then GCC is able to detect it.