Skip to content

Commit a7dd155

Browse files
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
1 parent e3a0777 commit a7dd155

File tree

8 files changed

+12
-40
lines changed

8 files changed

+12
-40
lines changed

csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/google/protobuf/compiler/cpp/file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ void FileGenerator::GenerateStaticInitializer(io::Printer* p) {
855855
}}},
856856
R"cc(
857857
PROTOBUF_ATTRIBUTE_INIT_PRIORITY$priority$ static ::std::false_type
858-
_static_init$priority$_ PROTOBUF_UNUSED =
858+
_static_init$priority$_ [[maybe_unused]] =
859859
($expr$, ::std::false_type{});
860860
)cc");
861861
// Reset the vector because we might be generating many files.

src/google/protobuf/compiler/java/java_features.pb.cc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/plugin.pb.cc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/descriptor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,7 @@ DescriptorBuilder::DescriptorBuilder(
48074807
// have to avoid registering these pre-main, because we need to ensure that
48084808
// the linker --gc-sections step can strip out the full runtime if it is
48094809
// unused.
4810-
PROTOBUF_UNUSED static std::true_type lazy_register =
4810+
[[maybe_unused]] static std::true_type lazy_register =
48114811
(internal::ExtensionSet::RegisterMessageExtension(
48124812
&FeatureSet::default_instance(), pb::cpp.number(),
48134813
FieldDescriptor::TYPE_MESSAGE, false, false,

src/google/protobuf/generated_message_tctable_lite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,8 +1566,8 @@ void EnsureArenaStringIsNotDefault(const MessageLite* msg,
15661566
}
15671567
}
15681568
// The rest do nothing.
1569-
PROTOBUF_UNUSED void EnsureArenaStringIsNotDefault(const MessageLite* msg,
1570-
void*) {}
1569+
[[maybe_unused]] void EnsureArenaStringIsNotDefault(const MessageLite* msg,
1570+
void*) {}
15711571

15721572
} // namespace
15731573

src/google/protobuf/message_unittest.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ TEST(MESSAGE_TEST_NAME, TestEnumParsers) {
15721572

15731573
constexpr int kInvalidValue = 0x900913;
15741574
auto* ref = obj.GetReflection();
1575-
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
1575+
[[maybe_unused]] auto* descriptor = obj.descriptor();
15761576
for (bool use_packed : {false, true}) {
15771577
SCOPED_TRACE(use_packed);
15781578
for (bool use_tail_field : {false, true}) {
@@ -1669,7 +1669,7 @@ TEST(MESSAGE_TEST_NAME, TestEnumParserForUnknownEnumValue) {
16691669
// For unknown enum values, for consistency we must include the
16701670
// int32_t enum value in the unknown field set, which might not be exactly the
16711671
// same as the input.
1672-
PROTOBUF_UNUSED auto* descriptor = non_dynamic.descriptor();
1672+
[[maybe_unused]] auto* descriptor = non_dynamic.descriptor();
16731673

16741674
const std::vector<const FieldDescriptor*> fields =
16751675
GetFields<UNITTEST::EnumParseTester>();
@@ -1722,7 +1722,7 @@ TEST(MESSAGE_TEST_NAME, TestBoolParsers) {
17221722
GetFields<UNITTEST::BoolParseTester>();
17231723

17241724
auto* ref = obj.GetReflection();
1725-
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
1725+
[[maybe_unused]] auto* descriptor = obj.descriptor();
17261726
for (bool use_tail_field : {false, true}) {
17271727
SCOPED_TRACE(use_tail_field);
17281728
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@@ -1786,7 +1786,7 @@ TEST(MESSAGE_TEST_NAME, TestInt32Parsers) {
17861786
GetFields<UNITTEST::Int32ParseTester>();
17871787

17881788
auto* ref = obj.GetReflection();
1789-
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
1789+
[[maybe_unused]] auto* descriptor = obj.descriptor();
17901790
for (bool use_tail_field : {false, true}) {
17911791
SCOPED_TRACE(use_tail_field);
17921792
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@@ -1851,7 +1851,7 @@ TEST(MESSAGE_TEST_NAME, TestInt64Parsers) {
18511851
GetFields<UNITTEST::Int64ParseTester>();
18521852

18531853
auto* ref = obj.GetReflection();
1854-
PROTOBUF_UNUSED auto* descriptor = obj.descriptor();
1854+
[[maybe_unused]] auto* descriptor = obj.descriptor();
18551855
for (bool use_tail_field : {false, true}) {
18561856
SCOPED_TRACE(use_tail_field);
18571857
for (int non_canonical_bytes = 0; non_canonical_bytes < 10;
@@ -1955,7 +1955,7 @@ TEST(MESSAGE_TEST_NAME, TestRepeatedStringParsers) {
19551955
"abcdefghijklmnopqrstuvwxyz"
19561956
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
19571957

1958-
PROTOBUF_UNUSED const auto* const descriptor =
1958+
[[maybe_unused]] const auto* const descriptor =
19591959
UNITTEST::StringParseTester::descriptor();
19601960

19611961
const std::vector<const FieldDescriptor*> fields =

src/google/protobuf/port_def.inc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
598598
#define PROTOBUF_TC_PARAM_NO_DATA_PASS \
599599
msg, ptr, ctx, ::google::protobuf::internal::TcFieldData::DefaultInit(), table, hasbits
600600

601-
#ifdef PROTOBUF_UNUSED
602-
#error PROTOBUF_UNUSED was previously defined
603-
#endif
604-
#if ABSL_HAVE_CPP_ATTRIBUTE(maybe_unused) || (PROTOBUF_MSC_VER_MIN(1911))
605-
#define PROTOBUF_UNUSED [[maybe_unused]]
606-
#elif ABSL_HAVE_ATTRIBUTE(unused) || defined(__GNUC__)
607-
#define PROTOBUF_UNUSED __attribute__((__unused__))
608-
#else
609-
#define PROTOBUF_UNUSED
610-
#endif
611-
612601
// For the toolchains that support it, evaluates to `true` if the input is
613602
// determined to be a compile time constant after optimizations have happened
614603
// (like inlining and constant propagation). A `false` result means that the

0 commit comments

Comments
 (0)