Work around -Werror=type-limits under gcc 10.2 (#8092)

* Work around `-Werror=type-limits` under gcc 10.2

This is an error when tag is greater than 128 under gcc 10.2:   `if (tag < 128) return *ptr == tag;`
It's an error even though the comparison occurs in a branch of code we know won't be taken.  See https://godbolt.org/z/1eaP86
This works around the problem by casting `tag` to the same type as `*ptr`.
pull/8098/head
Jorg Brown 4 years ago committed by GitHub
parent 51b620ac96
commit 3f91c10f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/google/protobuf/parse_context.h

@ -428,7 +428,7 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream {
template <uint32 tag>
bool ExpectTag(const char* ptr) {
if (tag < 128) {
return *ptr == tag;
return *ptr == static_cast<char>(tag);
} else {
static_assert(tag < 128 * 128, "We only expect tags for 1 or 2 bytes");
char buf[2] = {static_cast<char>(tag | 0x80), static_cast<char>(tag >> 7)};

Loading…
Cancel
Save