From 88ec26fe07d14753ac7820957a5754cf51a8607b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 28 Dec 2022 15:22:43 -0800 Subject: [PATCH] Correct HasBitVars logic to reflect the fact that stripped fields may return true for HasHasbit. PiperOrigin-RevId: 498258269 --- src/google/protobuf/compiler/cpp/field.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index f01850f36f..96a6bebdcf 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -210,13 +210,14 @@ std::unique_ptr MakeGenerator(const FieldDescriptor* field, void HasBitVars(const FieldDescriptor* field, const Options& opts, absl::optional idx, std::vector& vars) { - if (!internal::cpp::HasHasbit(field)) { - GOOGLE_ABSL_CHECK(!idx.has_value()); + if (!idx.has_value()) { vars.emplace_back("set_hasbit", ""); vars.emplace_back("clear_hasbit", ""); return; } + GOOGLE_ABSL_CHECK(internal::cpp::HasHasbit(field)); + int32_t index = *idx / 32; std::string mask = absl::StrFormat("0x%08xu", 1u << (*idx % 32));