[Bug c++/104359] GCC Treats bool with value != 1 as falsey when picking branches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104359 Martin Sebor changed: What|Removed |Added CC||msebor at gcc dot gnu.org --- Comment #5 from Martin Sebor --- It is undefined but the issue/question keeps coming up. The store that makes the subsequent read undefined is clearly visible in the IL at all optimization levels so it would be quite easy to issue a helpful warning for the code.
[Bug c++/104359] GCC Treats bool with value != 1 as falsey when picking branches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104359 --- Comment #4 from Jonathan Wakely --- (In reply to Will Usher from comment #0) > However, b's "value" is 255, which should evaluate to "true". No. The only valid values of bool are true and false. If you set its bits to some other value representation which does not correspond to either the 'true' value or the 'false' value, you do not have an object of type bool, you have garbage. It's possible that a C++ implementation would use 0x for one of true or false, in which case your memcpy would be valid. But that's not the case for GCC.
[Bug c++/104359] GCC Treats bool with value != 1 as falsey when picking branches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104359 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|WAITING |RESOLVED --- Comment #3 from Andrew Pinski --- Closing as requested.
[Bug c++/104359] GCC Treats bool with value != 1 as falsey when picking branches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104359 --- Comment #2 from Will Usher --- Oh gotcha, then this can be closed.
[Bug c++/104359] GCC Treats bool with value != 1 as falsey when picking branches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104359 Andrew Pinski changed: What|Removed |Added Ever confirmed|0 |1 Last reconfirmed||2022-02-03 Status|UNCONFIRMED |WAITING --- Comment #1 from Andrew Pinski --- This is undefined behavior so anything can happen. Why do you think GCC should act consistent here? Using -fsanitize=undefined, I get: /app/example.cpp:9:9: runtime error: load of value 255, which is not a valid value for type 'bool' /app/example.cpp:14:5: runtime error: load of value 255, which is not a valid value for type 'bool'