From d326c1d6da46ad55f9502eb185facd506fc7efa6 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Mon, 15 Dec 2025 07:50:39 -0800 Subject: [PATCH] Prepare to make many APIs [[nodiscard]]. PiperOrigin-RevId: 844770264 --- benchmarks/benchmark.cc | 9 +++---- benchmarks/gen_protobuf_binary_cc.py | 4 ++-- lua/upbc.cc | 3 ++- python/google/protobuf/proto_api.cc | 12 ++++++---- python/google/protobuf/pyext/descriptor.cc | 6 +++-- .../google/protobuf/pyext/message_module.cc | 6 +++-- .../compiler/csharp/csharp_field_base.cc | 6 +++-- .../generated_message_reflection_unittest.cc | 2 ++ src/google/protobuf/io/coded_stream.cc | 15 ++++++++---- .../protobuf/io/coded_stream_unittest.cc | 24 ++++++++++++------- .../protobuf/io/test_zero_copy_stream_test.cc | 12 +++++----- .../protobuf/io/zero_copy_stream_impl_lite.cc | 6 +++-- .../protobuf/json/internal/untyped_message.cc | 6 +++-- src/google/protobuf/lite_unittest.cc | 5 ++-- src/google/protobuf/message_lite.cc | 12 ++++++---- src/google/protobuf/message_unittest.inc | 2 +- src/google/protobuf/no_field_presence_test.cc | 3 +++ src/google/protobuf/parse_context.cc | 6 +++-- src/google/protobuf/proto3_arena_unittest.cc | 11 +++++---- src/google/protobuf/wire_format_unittest.h | 4 ++-- upb/util/def_to_proto_test.cc | 4 ++-- upb/util/def_to_proto_test.h | 4 ++-- 22 files changed, 102 insertions(+), 60 deletions(-) diff --git a/benchmarks/benchmark.cc b/benchmarks/benchmark.cc index 115af6711c..744d24d7a0 100644 --- a/benchmarks/benchmark.cc +++ b/benchmarks/benchmark.cc @@ -328,9 +328,10 @@ BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, InitBlock, Alias); static void BM_SerializeDescriptor_Proto2(benchmark::State& state) { upb_benchmark::FileDescriptorProto proto; - proto.ParseFromString(absl::string_view(descriptor.data, descriptor.size)); + (void)proto.ParseFromString( + absl::string_view(descriptor.data, descriptor.size)); for (auto _ : state) { - proto.SerializePartialToArray(buf, sizeof(buf)); + (void)proto.SerializePartialToArray(buf, sizeof(buf)); benchmark::DoNotOptimize(buf); } state.SetBytesProcessed(state.iterations() * descriptor.size); @@ -420,7 +421,7 @@ BENCHMARK(BM_JsonParse_Upb); static void BM_JsonParse_Proto2(benchmark::State& state) { protobuf::FileDescriptorProto proto; absl::string_view input(descriptor.data, descriptor.size); - proto.ParseFromString(input); + (void)proto.ParseFromString(input); std::string json; ABSL_CHECK_OK(google::protobuf::json::MessageToJsonString(proto, &json)); for (auto _ : state) { @@ -461,7 +462,7 @@ BENCHMARK(BM_JsonSerialize_Upb); static void BM_JsonSerialize_Proto2(benchmark::State& state) { protobuf::FileDescriptorProto proto; absl::string_view input(descriptor.data, descriptor.size); - proto.ParseFromString(input); + (void)proto.ParseFromString(input); std::string json; for (auto _ : state) { json.clear(); diff --git a/benchmarks/gen_protobuf_binary_cc.py b/benchmarks/gen_protobuf_binary_cc.py index ece5b2372e..be4df27f0b 100644 --- a/benchmarks/gen_protobuf_binary_cc.py +++ b/benchmarks/gen_protobuf_binary_cc.py @@ -54,8 +54,8 @@ def RefMessage(name): print(''' {{ {name} proto; - proto.ParseFromArray(buf, 0); - proto.SerializePartialToArray(&buf[0], 0); + (void)proto.ParseFromArray(buf, 0); + (void)proto.SerializePartialToArray(&buf[0], 0); }} '''.format(name=name)) diff --git a/lua/upbc.cc b/lua/upbc.cc index 5193614d50..66e9a040b3 100644 --- a/lua/upbc.cc +++ b/lua/upbc.cc @@ -99,7 +99,8 @@ bool LuaGenerator::Generate(const protobuf::FileDescriptor* file, protobuf::FileDescriptorProto file_proto; file->CopyTo(&file_proto); std::string file_data; - file_proto.SerializeToString(&file_data); + // TODO: Remove this suppression. + (void)file_proto.SerializeToString(&file_data); printer.Print("local descriptor = table.concat({\n"); absl::string_view data(file_data); diff --git a/python/google/protobuf/proto_api.cc b/python/google/protobuf/proto_api.cc index ef2ee361c9..0a78368778 100644 --- a/python/google/protobuf/proto_api.cc +++ b/python/google/protobuf/proto_api.cc @@ -46,7 +46,8 @@ PythonMessageMutator::~PythonMessageMutator() { // check. if (!PyErr_Occurred() && owned_msg_ != nullptr) { std::string wire; - message_->SerializePartialToString(&wire); + // TODO: Remove this suppression. + (void)message_->SerializePartialToString(&wire); PyObject* py_wire = PyBytes_FromStringAndSize( wire.data(), static_cast(wire.size())); PyObject* parse = @@ -113,20 +114,23 @@ bool PythonConstMessagePointer::NotChanged() { // serialize result may still diff between languages. So parse to // another c++ message for compare. std::unique_ptr parsed_msg(owned_msg_->New()); - parsed_msg->ParsePartialFromString( + // TODO: Remove this suppression. + (void)parsed_msg->ParsePartialFromString( absl::string_view(data, static_cast(len))); std::string wire_other; google::protobuf::io::StringOutputStream stream_other(&wire_other); google::protobuf::io::CodedOutputStream output_other(&stream_other); output_other.SetSerializationDeterministic(true); - parsed_msg->SerializePartialToCodedStream(&output_other); + // TODO: Remove this suppression. + (void)parsed_msg->SerializePartialToCodedStream(&output_other); output_other.Trim(); std::string wire; google::protobuf::io::StringOutputStream stream(&wire); google::protobuf::io::CodedOutputStream output(&stream); output.SetSerializationDeterministic(true); - owned_msg_->SerializePartialToCodedStream(&output); + // TODO: Remove this suppression. + (void)owned_msg_->SerializePartialToCodedStream(&output); output.Trim(); if (wire == wire_other) { diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 525256a619..8763acac2f 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -228,7 +228,8 @@ bool Reparse(PyMessageFactory* message_factory, const Message& from, Message* to) { // Reparse message. std::string serialized; - from.SerializeToString(&serialized); + // TODO: Remove this suppression. + (void)from.SerializeToString(&serialized); io::CodedInputStream input( reinterpret_cast(serialized.c_str()), serialized.size()); input.SetExtensionRegistry(message_factory->pool->pool, @@ -1490,7 +1491,8 @@ static PyObject* GetSerializedPb(PyFileDescriptor* self, void* closure) { FileDescriptorProto file_proto; _GetDescriptor(self)->CopyTo(&file_proto); std::string contents; - file_proto.SerializePartialToString(&contents); + // TODO: Remove this suppression. + (void)file_proto.SerializePartialToString(&contents); self->serialized_pb = PyBytes_FromStringAndSize( contents.c_str(), static_cast(contents.size())); if (self->serialized_pb == nullptr) { diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc index ae50346fad..919cb742d7 100644 --- a/python/google/protobuf/pyext/message_module.cc +++ b/python/google/protobuf/pyext/message_module.cc @@ -285,8 +285,10 @@ absl::StatusOr CreateNewMessage(PyObject* py_msg) { bool CopyToOwnedMsg(google::protobuf::Message** copy, const google::protobuf::Message& message) { *copy = message.New(); std::string wire; - message.SerializePartialToString(&wire); - (*copy)->ParsePartialFromString(wire); + // TODO: Remove this suppression. + (void)message.SerializePartialToString(&wire); + // TODO: Remove this suppression. + (void)(*copy)->ParsePartialFromString(wire); return true; } diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 8bbe341905..d6435c20f1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -42,7 +42,8 @@ void FieldGeneratorBase::SetCommonFieldVariables( } uint tag = internal::WireFormat::MakeTag(descriptor_); uint8_t tag_array[5]; - io::CodedOutputStream::WriteTagToArray(tag, tag_array); + // TODO: Remove this suppression. + (void)io::CodedOutputStream::WriteTagToArray(tag, tag_array); std::string tag_bytes = absl::StrCat(tag_array[0]); for (int i = 1; i < part_tag_size; i++) { absl::StrAppend(&tag_bytes, ", ", tag_array[i]); @@ -56,7 +57,8 @@ void FieldGeneratorBase::SetCommonFieldVariables( tag = internal::WireFormatLite::MakeTag( descriptor_->number(), internal::WireFormatLite::WIRETYPE_END_GROUP); - io::CodedOutputStream::WriteTagToArray(tag, tag_array); + // TODO: Remove this suppression. + (void)io::CodedOutputStream::WriteTagToArray(tag, tag_array); tag_bytes = absl::StrCat(tag_array[0]); for (int i = 1; i < part_tag_size; i++) { absl::StrAppend(&tag_bytes, ", ", tag_array[i]); diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index 600215760b..695f42d09b 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -1432,7 +1432,9 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) { TEST(GeneratedMessageReflectionTest, UsageErrors) { unittest::TestAllTypes message; +#ifndef NDEBUG unittest::ForeignMessage foreign; +#endif const Reflection* reflection = message.GetReflection(); const Descriptor* descriptor = message.GetDescriptor(); diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index 8caa4d9fe5..2d05fde5d6 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -214,7 +214,8 @@ bool CodedInputStream::SkipFallback(int count, int original_buffer_size) { // We hit the limit. Skip up to it then fail. if (bytes_until_limit > 0) { total_bytes_read_ = closest_limit; - input_->Skip(bytes_until_limit); + // TODO: Remove this suppression. + (void)input_->Skip(bytes_until_limit); } return false; } @@ -337,7 +338,8 @@ bool CodedInputStream::ReadCord(absl::Cord* output, int size) { const int available = closest_limit - total_bytes_read_; if (ABSL_PREDICT_FALSE(size > available)) { total_bytes_read_ = closest_limit; - input_->ReadCord(output, available); + // TODO: Remove this suppression. + (void)input_->ReadCord(output, available); return false; } total_bytes_read_ += size; @@ -359,7 +361,8 @@ bool CodedInputStream::ReadLittleEndian16Fallback(uint16_t* value) { if (!ReadRaw(bytes, kSize)) return false; ptr = bytes; } - ReadLittleEndian16FromArray(ptr, value); + // TODO: Remove this suppression. + (void)ReadLittleEndian16FromArray(ptr, value); return true; } @@ -377,7 +380,8 @@ bool CodedInputStream::ReadLittleEndian32Fallback(uint32_t* value) { if (!ReadRaw(bytes, kSize)) return false; ptr = bytes; } - ReadLittleEndian32FromArray(ptr, value); + // TODO: Remove this suppression. + (void)ReadLittleEndian32FromArray(ptr, value); return true; } @@ -395,7 +399,8 @@ bool CodedInputStream::ReadLittleEndian64Fallback(uint64_t* value) { if (!ReadRaw(bytes, kSize)) return false; ptr = bytes; } - ReadLittleEndian64FromArray(ptr, value); + // TODO: Remove this suppression. + (void)ReadLittleEndian64FromArray(ptr, value); return true; } diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc index 218e8632a1..85af95e462 100644 --- a/src/google/protobuf/io/coded_stream_unittest.cc +++ b/src/google/protobuf/io/coded_stream_unittest.cc @@ -179,7 +179,8 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) { int count_; } in; CodedInputStream input(&in); - input.ReadTagNoLastTag(); + // TODO: Remove this suppression. + (void)input.ReadTagNoLastTag(); EXPECT_TRUE(input.ConsumedEntireMessage()); } @@ -200,7 +201,8 @@ TEST_P(VarintCases, ExpectTag) { // Read one byte to force coded_input.Refill() to be called. Otherwise, // ExpectTag() will return a false negative. uint8_t dummy; - coded_input.ReadRaw(&dummy, 1); + // TODO: Remove this suppression. + (void)coded_input.ReadRaw(&dummy, 1); EXPECT_EQ((uint)'\0', (uint)dummy); uint32_t expected_value = static_cast(kVarintCases_case.value); @@ -831,7 +833,8 @@ TEST_P(BlockSizes, ReadStringReservesMemoryOnPushedLimit) { { CodedInputStream coded_input(&input); - coded_input.PushLimit(sizeof(buffer_)); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(sizeof(buffer_)); std::string str; EXPECT_TRUE(coded_input.ReadString(&str, strlen(kRawBytes))); @@ -876,7 +879,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsNegative) { { CodedInputStream coded_input(&input); - coded_input.PushLimit(sizeof(buffer_)); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(sizeof(buffer_)); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, -1)); @@ -896,7 +900,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsLarge) { { CodedInputStream coded_input(&input); - coded_input.PushLimit(sizeof(buffer_)); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(sizeof(buffer_)); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); @@ -913,7 +918,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsOverTheLimit) { { CodedInputStream coded_input(&input); - coded_input.PushLimit(16); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(16); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, strlen(kRawBytes))); @@ -954,7 +960,8 @@ TEST_F(CodedStreamTest, { CodedInputStream coded_input(&input); - coded_input.PushLimit(sizeof(buffer_)); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(sizeof(buffer_)); coded_input.SetTotalBytesLimit(16); std::string str; @@ -976,7 +983,8 @@ TEST_F(CodedStreamTest, { CodedInputStream coded_input(&input); - coded_input.PushLimit(16); + // TODO: Remove this suppression. + (void)coded_input.PushLimit(16); coded_input.SetTotalBytesLimit(sizeof(buffer_)); EXPECT_EQ(sizeof(buffer_), coded_input.BytesUntilTotalBytesLimit()); diff --git a/src/google/protobuf/io/test_zero_copy_stream_test.cc b/src/google/protobuf/io/test_zero_copy_stream_test.cc index bc900a1faa..1ee846f587 100644 --- a/src/google/protobuf/io/test_zero_copy_stream_test.cc +++ b/src/google/protobuf/io/test_zero_copy_stream_test.cc @@ -62,8 +62,8 @@ TEST(TestZeroCopyInputStreamTest, NextChecksPreconditions) { std::make_unique(std::vector{}); const void* data; int size; - EXPECT_DEATH(stream->Next(nullptr, &size), "data must not be null"); - EXPECT_DEATH(stream->Next(&data, nullptr), "size must not be null"); + EXPECT_DEATH((void)stream->Next(nullptr, &size), "data must not be null"); + EXPECT_DEATH((void)stream->Next(&data, nullptr), "size must not be null"); } #endif // GTEST_HAS_DEATH_TEST @@ -119,7 +119,7 @@ TEST(TestZeroCopyInputStreamTest, BackUpChecksPreconditions) { "The last call was not a successful Next\\(\\)"); EXPECT_THAT(CallNext(*stream), Optional(Eq("C"))); EXPECT_THAT(CallNext(*stream), Optional(Eq("D"))); - stream->Skip(1); + (void)stream->Skip(1); EXPECT_DEATH(stream->BackUp(0), "The last call was not a successful Next\\(\\)"); EXPECT_THAT(CallNext(*stream), Optional(Eq("FG"))); @@ -168,7 +168,7 @@ TEST(TestZeroCopyInputStreamTest, SkipWorks) { TEST(TestZeroCopyInputStreamTest, SkipChecksPreconditions) { std::unique_ptr stream = std::make_unique(std::vector{}); - EXPECT_DEATH(stream->Skip(-1), "count must not be negative"); + EXPECT_DEATH((void)stream->Skip(-1), "count must not be negative"); } #endif // GTEST_HAS_DEATH_TEST @@ -207,8 +207,8 @@ TEST(TestZeroCopyOutputStreamTest, NextChecksPreconditions) { std::make_unique(empty); void* data; int size; - EXPECT_DEATH(stream->Next(nullptr, &size), "data must not be null"); - EXPECT_DEATH(stream->Next(&data, nullptr), "size must not be null"); + EXPECT_DEATH((void)stream->Next(nullptr, &size), "data must not be null"); + EXPECT_DEATH((void)stream->Next(&data, nullptr), "size must not be null"); } #endif // GTEST_HAS_DEATH_TEST diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index be2918b904..b6ee766029 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -443,7 +443,8 @@ void LimitingInputStream::BackUp(int count) { bool LimitingInputStream::Skip(int count) { if (count > limit_) { if (limit_ < 0) return false; - input_->Skip(limit_); + // TODO: Remove this suppression. + (void)input_->Skip(limit_); limit_ = 0; return false; } else { @@ -468,7 +469,8 @@ bool LimitingInputStream::ReadCord(absl::Cord* cord, int count) { limit_ -= count; return true; } - input_->ReadCord(cord, limit_); + // TODO: Remove this suppression. + (void)input_->ReadCord(cord, limit_); limit_ = 0; return false; } diff --git a/src/google/protobuf/json/internal/untyped_message.cc b/src/google/protobuf/json/internal/untyped_message.cc index 3f1d77f63a..6c7607ed42 100644 --- a/src/google/protobuf/json/internal/untyped_message.cc +++ b/src/google/protobuf/json/internal/untyped_message.cc @@ -256,7 +256,8 @@ absl::Status UntypedMessage::Decode(io::CodedInputStream& stream, if (!stream.ReadVarint32(&x)) { return MakeUnexpectedEofError(); } - stream.Skip(x); + // TODO: Remove this suppression. + (void)stream.Skip(x); continue; } case WireFormatLite::WIRETYPE_START_GROUP: { @@ -516,7 +517,8 @@ absl::Status UntypedMessage::DecodeDelimited(io::CodedInputStream& stream, break; } } - stream.DecrementRecursionDepthAndPopLimit(limit); + // TODO: Remove this suppression. + (void)stream.DecrementRecursionDepthAndPopLimit(limit); return absl::OkStatus(); } diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 121b9c9d8f..9e3121d5d7 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -1399,8 +1399,9 @@ TEST(LiteTest, DynamicCastMessageInvalidReferenceType) { CastType1 test_type_1; const MessageLite& test_type_1_pointer_const_ref = test_type_1; #if defined(ABSL_HAVE_EXCEPTIONS) - EXPECT_THROW(DynamicCastMessage(test_type_1_pointer_const_ref), - std::bad_cast); + EXPECT_THROW( + (void)DynamicCastMessage(test_type_1_pointer_const_ref), + std::bad_cast); #elif defined(GTEST_HAS_DEATH_TEST) ASSERT_DEATH( (void)DynamicCastMessage(test_type_1_pointer_const_ref), diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 5c5656e8df..8987c3b405 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -289,7 +289,8 @@ class ZeroCopyCodedInputStream : public io::ZeroCopyInputStream { explicit ZeroCopyCodedInputStream(io::CodedInputStream* cis) : cis_(cis) {} bool Next(const void** data, int* size) final { if (!cis_->GetDirectBufferPointer(data, size)) return false; - cis_->Skip(*size); + // TODO: Remove this suppression. + (void)cis_->Skip(*size); return true; } void BackUp(int count) final { cis_->Advance(-count); } @@ -479,7 +480,8 @@ inline uint8_t* SerializeToArrayImpl(const MessageLite& msg, uint8_t* target, &stream, io::CodedOutputStream::IsDefaultSerializationDeterministic(), &ptr); ptr = msg._InternalSerialize(ptr, &out); - out.Trim(ptr); + // TODO: Remove this suppression. + (void)out.Trim(ptr); ABSL_DCHECK(!out.HadError() && stream.ByteCount() == size); return target + size; } else { @@ -549,7 +551,8 @@ bool MessageLite::SerializePartialToZeroCopyStream( output, io::CodedOutputStream::IsDefaultSerializationDeterministic(), &target); target = _InternalSerialize(target, &stream); - stream.Trim(target); + // TODO: Remove this suppression. + (void)stream.Trim(target); if (stream.HadError()) return false; return true; } @@ -690,7 +693,8 @@ bool MessageLite::AppendPartialToString(absl::Cord* output) const { target, static_cast(available.size()), &output_stream, io::CodedOutputStream::IsDefaultSerializationDeterministic(), &target); target = _InternalSerialize(target, &out); - out.Trim(target); + // TODO: Remove this suppression. + (void)out.Trim(target); if (out.HadError()) return false; *output = output_stream.Consume(); ABSL_DCHECK_EQ(output->size(), total_size); diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index d39bd76b40..9dd0c3ca1a 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -861,7 +861,7 @@ TEST(MESSAGE_TEST_NAME, DynamicCastMessageInvalidReferenceType) { UNITTEST::TestAllTypes test_all_types; const MessageLite& test_all_types_pointer_const_ref = test_all_types; #if defined(ABSL_HAVE_EXCEPTIONS) - EXPECT_THROW(DynamicCastMessage( + EXPECT_THROW((void)DynamicCastMessage( test_all_types_pointer_const_ref), std::bad_cast); #else diff --git a/src/google/protobuf/no_field_presence_test.cc b/src/google/protobuf/no_field_presence_test.cc index facdf5385e..2c803ace83 100644 --- a/src/google/protobuf/no_field_presence_test.cc +++ b/src/google/protobuf/no_field_presence_test.cc @@ -312,6 +312,7 @@ TEST(NoFieldPresenceTest, CopyTwiceDefaultStringFieldTest) { dst = src; dst = src; + (void)dst; } TEST(NoFieldPresenceTest, CopyTwiceAllocatedStringFieldTest) { @@ -325,6 +326,7 @@ TEST(NoFieldPresenceTest, CopyTwiceAllocatedStringFieldTest) { dst = src; dst = src; + (void)dst; } TEST(NoFieldPresenceTest, CopyTwiceEmptyStringFieldTest) { @@ -339,6 +341,7 @@ TEST(NoFieldPresenceTest, CopyTwiceEmptyStringFieldTest) { dst = src; dst = src; + (void)dst; } class NoFieldPresenceSwapFieldTest : public testing::Test { diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 09028921b2..1b58968b10 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -698,7 +698,8 @@ class UnknownFieldLiteParserHelper { if (unknown_ == nullptr) return; WriteVarint(num * 8 + 1, unknown_); char buffer[8]; - io::CodedOutputStream::WriteLittleEndian64ToArray( + // TODO: Remove this suppression. + (void)io::CodedOutputStream::WriteLittleEndian64ToArray( value, reinterpret_cast(buffer)); unknown_->append(buffer, 8); } @@ -724,7 +725,8 @@ class UnknownFieldLiteParserHelper { if (unknown_ == nullptr) return; WriteVarint(num * 8 + 5, unknown_); char buffer[4]; - io::CodedOutputStream::WriteLittleEndian32ToArray( + // TODO: Remove this suppression. + (void)io::CodedOutputStream::WriteLittleEndian32ToArray( value, reinterpret_cast(buffer)); unknown_->append(buffer, 4); } diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index aaaa16cc96..22de365c95 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -162,12 +162,13 @@ TEST(Proto3ArenaTest, GetArenaWithUnknown) { // Tests arena-allocated message and submessages. auto* arena_message1 = Arena::Create(&arena); - arena_message1->GetReflection()->MutableUnknownFields(arena_message1); + (void)arena_message1->GetReflection()->MutableUnknownFields(arena_message1); auto* arena_submessage1 = arena_message1->mutable_optional_foreign_message(); - arena_submessage1->GetReflection()->MutableUnknownFields(arena_submessage1); + (void)arena_submessage1->GetReflection()->MutableUnknownFields( + arena_submessage1); auto* arena_repeated_submessage1 = arena_message1->add_repeated_foreign_message(); - arena_repeated_submessage1->GetReflection()->MutableUnknownFields( + (void)arena_repeated_submessage1->GetReflection()->MutableUnknownFields( arena_repeated_submessage1); EXPECT_EQ(&arena, arena_message1->GetArena()); EXPECT_EQ(&arena, arena_submessage1->GetArena()); @@ -179,10 +180,10 @@ TEST(Proto3ArenaTest, GetArenaWithUnknown) { arena_message2->mutable_repeated_foreign_message()->AddAllocated( new ForeignMessage()); auto* submessage2 = arena_message2->mutable_optional_foreign_message(); - submessage2->GetReflection()->MutableUnknownFields(submessage2); + (void)submessage2->GetReflection()->MutableUnknownFields(submessage2); auto* repeated_submessage2 = arena_message2->mutable_repeated_foreign_message(0); - repeated_submessage2->GetReflection()->MutableUnknownFields( + (void)repeated_submessage2->GetReflection()->MutableUnknownFields( repeated_submessage2); EXPECT_EQ(nullptr, submessage2->GetArena()); EXPECT_EQ(nullptr, repeated_submessage2->GetArena()); diff --git a/src/google/protobuf/wire_format_unittest.h b/src/google/protobuf/wire_format_unittest.h index d34fadd441..51657f31b6 100644 --- a/src/google/protobuf/wire_format_unittest.h +++ b/src/google/protobuf/wire_format_unittest.h @@ -779,7 +779,7 @@ TYPED_TEST_P(WireFormatTest, ParseMessageSetWithDeepRecReverseOrder) { m->set_i(i); mset = m->mutable_recursive(); } - message_set.ByteSizeLong(); + EXPECT_GT(message_set.ByteSizeLong(), 0); // Serialize with reverse payload tag order io::StringOutputStream output_stream(&data); io::CodedOutputStream coded_output(&output_stream); @@ -834,7 +834,7 @@ TYPED_TEST_P(WireFormatTest, ParseFailMalformedMessageSetReverseOrder) { // SerializeReverseOrder() assumes "recursive" is always present. m->mutable_recursive(); - message_set.ByteSizeLong(); + EXPECT_GT(message_set.ByteSizeLong(), 0); // Serialize with reverse payload tag order io::StringOutputStream output_stream(&data); diff --git a/upb/util/def_to_proto_test.cc b/upb/util/def_to_proto_test.cc index c27f22c6fe..d824d434d3 100644 --- a/upb/util/def_to_proto_test.cc +++ b/upb/util/def_to_proto_test.cc @@ -39,7 +39,7 @@ const google::protobuf::Descriptor* AddMessageDescriptor(upb::MessageDefPtr msgd const char* buf = google_protobuf_FileDescriptorProto_serialize(upb_proto, tmp_arena.ptr(), &size); google::protobuf::FileDescriptorProto google_proto; - google_proto.ParseFromString(absl::string_view(buf, size)); + EXPECT_TRUE(google_proto.ParseFromString(absl::string_view(buf, size))); const google::protobuf::FileDescriptor* file_desc = pool->BuildFile(google_proto); EXPECT_TRUE(file_desc != nullptr); return pool->FindMessageTypeByName(msgdef.full_name()); @@ -60,7 +60,7 @@ std::unique_ptr ToProto(const upb_Message* msg, upb_EncodeStatus status = upb_Encode(msg, upb_MessageDef_MiniTable(msgdef), 0, arena.ptr(), &buf, &size); EXPECT_EQ(status, kUpb_EncodeStatus_Ok); - google_msg->ParseFromString(absl::string_view(buf, size)); + EXPECT_TRUE(google_msg->ParseFromString(absl::string_view(buf, size))); return google_msg; } diff --git a/upb/util/def_to_proto_test.h b/upb/util/def_to_proto_test.h index 02d34d2bd0..c2d6520add 100644 --- a/upb/util/def_to_proto_test.h +++ b/upb/util/def_to_proto_test.h @@ -65,7 +65,7 @@ static void AddFile(google::protobuf::FileDescriptorProto& file, upb::DefPool* p google::protobuf::FileDescriptorProto normalized_file; file_desc->CopyTo(&normalized_file); std::string serialized; - normalized_file.SerializeToString(&serialized); + (void)normalized_file.SerializeToString(&serialized); upb::Arena arena; upb::Status status; google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse( @@ -100,7 +100,7 @@ static void AddFile(google::protobuf::FileDescriptorProto& file, upb::DefPool* p // it may or may not be accepted, since upb does not perform as much // validation as proto2. However it must not crash. std::string serialized; - file.SerializeToString(&serialized); + (void)file.SerializeToString(&serialized); upb::Arena arena; upb::Status status; google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse(