Skip to content

Commit

Permalink
Use [[maybe_unused]] instead of PROTOBUF_UNUSED.
Browse files Browse the repository at this point in the history
With C++17 being the baseline, we should use [[maybe_unused]]
to shrink port_def.inc.

PiperOrigin-RevId: 693862958
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 6, 2024
1 parent e3a0777 commit a7dd155
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 40 deletions.
17 changes: 0 additions & 17 deletions csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/cpp/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/java/java_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/generated_message_tctable_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/google/protobuf/message_unittest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down Expand Up @@ -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>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
11 changes: 0 additions & 11 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7dd155

Please sign in to comment.