From 3f91c10f0daf8bfce21bb8a80bf3ecd20f83f625 Mon Sep 17 00:00:00 2001 From: Jorg Brown Date: Wed, 25 Nov 2020 17:31:49 -0800 Subject: [PATCH] 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`. --- src/google/protobuf/parse_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 661008589d..11eae7106f 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -428,7 +428,7 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { template bool ExpectTag(const char* ptr) { if (tag < 128) { - return *ptr == tag; + return *ptr == static_cast(tag); } else { static_assert(tag < 128 * 128, "We only expect tags for 1 or 2 bytes"); char buf[2] = {static_cast(tag | 0x80), static_cast(tag >> 7)};