Use [[maybe_unused]] instead of PROTOBUF_UNUSED.

With C++17 being the baseline, we should use [[maybe_unused]]
to shrink port_def.inc.

PiperOrigin-RevId: 693862958
pull/19146/head
Protobuf Team Bot 3 weeks ago committed by Copybara-Service
parent e3a0777b2c
commit a7dd1559ee
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 2
      src/google/protobuf/compiler/cpp/file.cc
  3. 2
      src/google/protobuf/compiler/java/java_features.pb.cc
  4. 2
      src/google/protobuf/compiler/plugin.pb.cc
  5. 2
      src/google/protobuf/descriptor.cc
  6. 4
      src/google/protobuf/generated_message_tctable_lite.cc
  7. 12
      src/google/protobuf/message_unittest.inc
  8. 11
      src/google/protobuf/port_def.inc

@ -1,17 +0,0 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#endregion
namespace Google.Protobuf.Reflection;
internal sealed partial class FeatureSetDescriptor
{
// Canonical serialized form of the edition defaults, generated by embed_edition_defaults.
private const string DefaultsBase64 =
"ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH";
}

@ -855,7 +855,7 @@ void FileGenerator::GenerateStaticInitializer(io::Printer* p) {
}}},
R"cc(
PROTOBUF_ATTRIBUTE_INIT_PRIORITY$priority$ static ::std::false_type
_static_init$priority$_ PROTOBUF_UNUSED =
_static_init$priority$_ [[maybe_unused]] =
($expr$, ::std::false_type{});
)cc");
// Reset the vector because we might be generating many files.

@ -439,7 +439,7 @@ namespace protobuf {
} // namespace google
// @@protoc_insertion_point(global_scope)
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type
_static_init2_ PROTOBUF_UNUSED =
_static_init2_ [[maybe_unused]] =
(::_pbi::AddDescriptors(&descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto),
::_pbi::ExtensionSet::RegisterMessageExtension(
&::google::protobuf::FeatureSet::default_instance(), 1001, 11,

@ -1830,7 +1830,7 @@ namespace protobuf {
} // namespace google
// @@protoc_insertion_point(global_scope)
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type
_static_init2_ PROTOBUF_UNUSED =
_static_init2_ [[maybe_unused]] =
(::_pbi::AddDescriptors(&descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto),
::std::false_type{});
#include "google/protobuf/port_undef.inc"

@ -4807,7 +4807,7 @@ DescriptorBuilder::DescriptorBuilder(
// have to avoid registering these pre-main, because we need to ensure that
// the linker --gc-sections step can strip out the full runtime if it is
// unused.
PROTOBUF_UNUSED static std::true_type lazy_register =
[[maybe_unused]] static std::true_type lazy_register =
(internal::ExtensionSet::RegisterMessageExtension(
&FeatureSet::default_instance(), pb::cpp.number(),
FieldDescriptor::TYPE_MESSAGE, false, false,

@ -1566,8 +1566,8 @@ void EnsureArenaStringIsNotDefault(const MessageLite* msg,
}
}
// The rest do nothing.
PROTOBUF_UNUSED void EnsureArenaStringIsNotDefault(const MessageLite* msg,
void*) {}
[[maybe_unused]] void EnsureArenaStringIsNotDefault(const MessageLite* msg,
void*) {}
} // namespace

@ -1572,7 +1572,7 @@ TEST(MESSAGE_TEST_NAME, TestEnumParsers) {
constexpr int kInvalidValue = 0x900913;
auto* ref = obj.GetReflection();
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
[[maybe_unused]] auto* descriptor = obj.descriptor();
for (bool use_packed : {false, true}) {
SCOPED_TRACE(use_packed);
for (bool use_tail_field : {false, true}) {
@ -1669,7 +1669,7 @@ TEST(MESSAGE_TEST_NAME, TestEnumParserForUnknownEnumValue) {
// For unknown enum values, for consistency we must include the
// int32_t enum value in the unknown field set, which might not be exactly the
// same as the input.
PROTOBUF_UNUSED auto* descriptor = non_dynamic.descriptor();
[[maybe_unused]] auto* descriptor = non_dynamic.descriptor();
const std::vector<const FieldDescriptor*> fields =
GetFields<UNITTEST::EnumParseTester>();
@ -1722,7 +1722,7 @@ TEST(MESSAGE_TEST_NAME, TestBoolParsers) {
GetFields<UNITTEST::BoolParseTester>();
auto* ref = obj.GetReflection();
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
[[maybe_unused]] auto* descriptor = obj.descriptor();
for (bool use_tail_field : {false, true}) {
SCOPED_TRACE(use_tail_field);
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@ -1786,7 +1786,7 @@ TEST(MESSAGE_TEST_NAME, TestInt32Parsers) {
GetFields<UNITTEST::Int32ParseTester>();
auto* ref = obj.GetReflection();
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
[[maybe_unused]] auto* descriptor = obj.descriptor();
for (bool use_tail_field : {false, true}) {
SCOPED_TRACE(use_tail_field);
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@ -1851,7 +1851,7 @@ TEST(MESSAGE_TEST_NAME, TestInt64Parsers) {
GetFields<UNITTEST::Int64ParseTester>();
auto* ref = obj.GetReflection();
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
[[maybe_unused]] auto* descriptor = obj.descriptor();
for (bool use_tail_field : {false, true}) {
SCOPED_TRACE(use_tail_field);
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@ -1955,7 +1955,7 @@ TEST(MESSAGE_TEST_NAME, TestRepeatedStringParsers) {
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
PROTOBUF_UNUSED const auto* const descriptor =
[[maybe_unused]] const auto* const descriptor =
UNITTEST::StringParseTester::descriptor();
const std::vector<const FieldDescriptor*> fields =

@ -598,17 +598,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#define PROTOBUF_TC_PARAM_NO_DATA_PASS \
msg, ptr, ctx, ::google::protobuf::internal::TcFieldData::DefaultInit(), table, hasbits
#ifdef PROTOBUF_UNUSED
#error PROTOBUF_UNUSED was previously defined
#endif
#if ABSL_HAVE_CPP_ATTRIBUTE(maybe_unused) || (PROTOBUF_MSC_VER_MIN(1911))
#define PROTOBUF_UNUSED [[maybe_unused]]
#elif ABSL_HAVE_ATTRIBUTE(unused) || defined(__GNUC__)
#define PROTOBUF_UNUSED __attribute__((__unused__))
#else
#define PROTOBUF_UNUSED
#endif
// For the toolchains that support it, evaluates to `true` if the input is
// determined to be a compile time constant after optimizations have happened
// (like inlining and constant propagation). A `false` result means that the

Loading…
Cancel
Save