[Bug c/67433] ?: expression returns unexpected value when condition is a bool variable which memory is not true/false
xuejuncao at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Sep 2 08:11:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433
--- Comment #3 from xuejuncao <xuejuncao at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Bool can only be 0 or 1, any other value causes undefined behavior.
but it seems like a trap, the below code will not work fine, and will make
program abort.
(expect to write "1/0" that only takes 1 byte, but write 2 bytes when value is
negative)
https://github.com/google/protobuf/blob/master/src/google/protobuf/wire_format_lite_inl.h
inline void WireFormatLite::WriteBoolNoTag(bool value,
io::CodedOutputStream* output) {
output->WriteVarint32(value ? 1 : 0);
}
More information about the Gcc-bugs
mailing list