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);
}

Reply via email to