From c6f7905a30c10f44224ff0145f097bca6d4c5f76 Mon Sep 17 00:00:00 2001 From: Herman Lee Date: Thu, 30 Jun 2022 11:31:38 -0700 Subject: [PATCH] Fix libprotobuf warnings Summary: Updating to the 3.19 version of protobuf from upstream results in some compiler errors about shadowing _cache_size_. This seems related to https://github.com/protocolbuffers/protobuf/issues/9378. The code around this area in the latest versions contain some fixes and those changes are applied here. Reviewed By: luqun Differential Revision: D37367670 --- .../src/google/protobuf/compiler/cpp/cpp_message.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extra/protobuf/protobuf-3.19.4/src/google/protobuf/compiler/cpp/cpp_message.cc b/extra/protobuf/protobuf-3.19.4/src/google/protobuf/compiler/cpp/cpp_message.cc index 70d8a57e3a9e..7fa1556f00ce 100644 --- a/extra/protobuf/protobuf-3.19.4/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/extra/protobuf/protobuf-3.19.4/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -1866,7 +1866,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { // Prepare decls for _cached_size_ and _has_bits_. Their position in the // output will be determined later. - bool need_to_emit_cached_size = true; + bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_); const std::string cached_size_decl = "mutable ::$proto_ns$::internal::CachedSize _cached_size_;\n"; @@ -1917,8 +1917,10 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { // _cached_size_ together with _has_bits_ improves cache locality despite // potential alignment padding. format(has_bits_decl.c_str()); - format(cached_size_decl.c_str()); - need_to_emit_cached_size = false; + if (need_to_emit_cached_size) { + format(cached_size_decl.c_str()); + need_to_emit_cached_size = false; + } } // Field members: