diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 8ec50eda5c..2189ee3e46 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -344,7 +344,7 @@ struct PROTOBUF_EXPORT ArenaStringPtr { // Own()'d by any arena. If the field is not set, this returns nullptr. The // caller retains ownership. Clears this field back to the default state. // Used to implement release_() methods on generated classes. - PROTOBUF_NODISCARD std::string* Release(); + [[nodiscard]] std::string* Release(); // Takes a std::string that is heap-allocated, and takes ownership. The // std::string's destructor is registered with the arena. Used to implement diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 7bfdaba27e..b52edfade9 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -164,7 +164,7 @@ void SingularMessage::GenerateAccessorDeclarations(io::Printer* p) const { p->Emit(R"cc( $DEPRECATED$ const $Submsg$& $name$() const; - $DEPRECATED$ PROTOBUF_NODISCARD $Submsg$* $release_name$(); + $DEPRECATED$ [[nodiscard]] $Submsg$* $release_name$(); $DEPRECATED$ $Submsg$* $mutable_name$(); $DEPRECATED$ void $set_allocated_name$($Submsg$* value); $DEPRECATED$ void $unsafe_arena_set_allocated_name$($Submsg$* value); diff --git a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc index 79828a558c..624d466c6a 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc @@ -270,7 +270,7 @@ void SingularString::GenerateAccessorDeclarations(io::Printer* p) const { template $DEPRECATED$ void $set_name$(Arg_&& arg, Args_... args); $DEPRECATED$ std::string* $mutable_name$(); - $DEPRECATED$ PROTOBUF_NODISCARD std::string* $release_name$(); + $DEPRECATED$ [[nodiscard]] std::string* $release_name$(); $DEPRECATED$ void $set_allocated_name$(std::string* value); private: diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 76ebd04b09..5e81260dd2 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -939,12 +939,10 @@ class PROTOC_EXPORT Formatter { Formatter* format_; }; - PROTOBUF_NODISCARD ScopedIndenter ScopedIndent() { - return ScopedIndenter(this); - } + [[nodiscard]] ScopedIndenter ScopedIndent() { return ScopedIndenter(this); } template - PROTOBUF_NODISCARD ScopedIndenter ScopedIndent(const char* format, - const Args&&... args) { + [[nodiscard]] ScopedIndenter ScopedIndent(const char* format, + const Args&&... args) { (*this)(format, static_cast(args)...); return ScopedIndenter(this); } diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index f5337f5da4..cebb88003a 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -960,11 +960,9 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, - _field_type, _is_packed>& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const $pbi$::ExtensionIdentifier< + $Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) { $WeakDescriptorSelfPin$; $annotate_extension_release$; return _proto_TypeTraits::Release(id.number(), _field_type, &$extensions$); diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index f6dd4ae06f..f6158e5ba4 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -289,7 +289,7 @@ class PROTOC_EXPORT Version final template void set_suffix(Arg_&& arg, Args_... args); std::string* mutable_suffix(); - PROTOBUF_NODISCARD std::string* release_suffix(); + [[nodiscard]] std::string* release_suffix(); void set_allocated_suffix(std::string* value); private: @@ -529,7 +529,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -545,7 +545,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final template void set_insertion_point(Arg_&& arg, Args_... args); std::string* mutable_insertion_point(); - PROTOBUF_NODISCARD std::string* release_insertion_point(); + [[nodiscard]] std::string* release_insertion_point(); void set_allocated_insertion_point(std::string* value); private: @@ -561,7 +561,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final template void set_content(Arg_&& arg, Args_... args); std::string* mutable_content(); - PROTOBUF_NODISCARD std::string* release_content(); + [[nodiscard]] std::string* release_content(); void set_allocated_content(std::string* value); private: @@ -574,7 +574,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final bool has_generated_code_info() const; void clear_generated_code_info() ; const ::google::protobuf::GeneratedCodeInfo& generated_code_info() const; - PROTOBUF_NODISCARD ::google::protobuf::GeneratedCodeInfo* release_generated_code_info(); + [[nodiscard]] ::google::protobuf::GeneratedCodeInfo* release_generated_code_info(); ::google::protobuf::GeneratedCodeInfo* mutable_generated_code_info(); void set_allocated_generated_code_info(::google::protobuf::GeneratedCodeInfo* value); void unsafe_arena_set_allocated_generated_code_info(::google::protobuf::GeneratedCodeInfo* value); @@ -822,7 +822,7 @@ class PROTOC_EXPORT CodeGeneratorResponse final template void set_error(Arg_&& arg, Args_... args); std::string* mutable_error(); - PROTOBUF_NODISCARD std::string* release_error(); + [[nodiscard]] std::string* release_error(); void set_allocated_error(std::string* value); private: @@ -1125,7 +1125,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final template void set_parameter(Arg_&& arg, Args_... args); std::string* mutable_parameter(); - PROTOBUF_NODISCARD std::string* release_parameter(); + [[nodiscard]] std::string* release_parameter(); void set_allocated_parameter(std::string* value); private: @@ -1138,7 +1138,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final bool has_compiler_version() const; void clear_compiler_version() ; const ::google::protobuf::compiler::Version& compiler_version() const; - PROTOBUF_NODISCARD ::google::protobuf::compiler::Version* release_compiler_version(); + [[nodiscard]] ::google::protobuf::compiler::Version* release_compiler_version(); ::google::protobuf::compiler::Version* mutable_compiler_version(); void set_allocated_compiler_version(::google::protobuf::compiler::Version* value); void unsafe_arena_set_allocated_compiler_version(::google::protobuf::compiler::Version* value); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index e2df612a74..c01af468b7 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1035,7 +1035,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final template void set_name_part(Arg_&& arg, Args_... args); std::string* mutable_name_part(); - PROTOBUF_NODISCARD std::string* release_name_part(); + [[nodiscard]] std::string* release_name_part(); void set_allocated_name_part(std::string* value); private: @@ -1310,7 +1310,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final template void set_leading_comments(Arg_&& arg, Args_... args); std::string* mutable_leading_comments(); - PROTOBUF_NODISCARD std::string* release_leading_comments(); + [[nodiscard]] std::string* release_leading_comments(); void set_allocated_leading_comments(std::string* value); private: @@ -1326,7 +1326,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final template void set_trailing_comments(Arg_&& arg, Args_... args); std::string* mutable_trailing_comments(); - PROTOBUF_NODISCARD std::string* release_trailing_comments(); + [[nodiscard]] std::string* release_trailing_comments(); void set_allocated_trailing_comments(std::string* value); private: @@ -1575,7 +1575,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final template void set_source_file(Arg_&& arg, Args_... args); std::string* mutable_source_file(); - PROTOBUF_NODISCARD std::string* release_source_file(); + [[nodiscard]] std::string* release_source_file(); void set_allocated_source_file(std::string* value); private: @@ -1817,7 +1817,7 @@ class PROTOBUF_EXPORT FieldOptions_FeatureSupport final template void set_deprecation_warning(Arg_&& arg, Args_... args); std::string* mutable_deprecation_warning(); - PROTOBUF_NODISCARD std::string* release_deprecation_warning(); + [[nodiscard]] std::string* release_deprecation_warning(); void set_allocated_deprecation_warning(std::string* value); private: @@ -2055,7 +2055,7 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final template void set_value(Arg_&& arg, Args_... args); std::string* mutable_value(); - PROTOBUF_NODISCARD std::string* release_value(); + [[nodiscard]] std::string* release_value(); void set_allocated_value(std::string* value); private: @@ -2541,11 +2541,9 @@ class PROTOBUF_EXPORT FeatureSet final } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + FeatureSet, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template void set_full_name(Arg_&& arg, Args_... args); std::string* mutable_full_name(); - PROTOBUF_NODISCARD std::string* release_full_name(); + [[nodiscard]] std::string* release_full_name(); void set_allocated_full_name(std::string* value); private: @@ -2855,7 +2853,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final template void set_type(Arg_&& arg, Args_... args); std::string* mutable_type(); - PROTOBUF_NODISCARD std::string* release_type(); + [[nodiscard]] std::string* release_type(); void set_allocated_type(std::string* value); private: @@ -3540,7 +3538,7 @@ class PROTOBUF_EXPORT UninterpretedOption final template void set_identifier_value(Arg_&& arg, Args_... args); std::string* mutable_identifier_value(); - PROTOBUF_NODISCARD std::string* release_identifier_value(); + [[nodiscard]] std::string* release_identifier_value(); void set_allocated_identifier_value(std::string* value); private: @@ -3556,7 +3554,7 @@ class PROTOBUF_EXPORT UninterpretedOption final template void set_string_value(Arg_&& arg, Args_... args); std::string* mutable_string_value(); - PROTOBUF_NODISCARD std::string* release_string_value(); + [[nodiscard]] std::string* release_string_value(); void set_allocated_string_value(std::string* value); private: @@ -3572,7 +3570,7 @@ class PROTOBUF_EXPORT UninterpretedOption final template void set_aggregate_value(Arg_&& arg, Args_... args); std::string* mutable_aggregate_value(); - PROTOBUF_NODISCARD std::string* release_aggregate_value(); + [[nodiscard]] std::string* release_aggregate_value(); void set_allocated_aggregate_value(std::string* value); private: @@ -3911,11 +3909,9 @@ class PROTOBUF_EXPORT SourceCodeInfo final } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + SourceCodeInfo, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + ServiceOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + OneofOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + MethodOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + MessageOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template void set_java_package(Arg_&& arg, Args_... args); std::string* mutable_java_package(); - PROTOBUF_NODISCARD std::string* release_java_package(); + [[nodiscard]] std::string* release_java_package(); void set_allocated_java_package(std::string* value); private: @@ -6454,7 +6442,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_java_outer_classname(Arg_&& arg, Args_... args); std::string* mutable_java_outer_classname(); - PROTOBUF_NODISCARD std::string* release_java_outer_classname(); + [[nodiscard]] std::string* release_java_outer_classname(); void set_allocated_java_outer_classname(std::string* value); private: @@ -6470,7 +6458,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_go_package(Arg_&& arg, Args_... args); std::string* mutable_go_package(); - PROTOBUF_NODISCARD std::string* release_go_package(); + [[nodiscard]] std::string* release_go_package(); void set_allocated_go_package(std::string* value); private: @@ -6486,7 +6474,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_objc_class_prefix(Arg_&& arg, Args_... args); std::string* mutable_objc_class_prefix(); - PROTOBUF_NODISCARD std::string* release_objc_class_prefix(); + [[nodiscard]] std::string* release_objc_class_prefix(); void set_allocated_objc_class_prefix(std::string* value); private: @@ -6502,7 +6490,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_csharp_namespace(Arg_&& arg, Args_... args); std::string* mutable_csharp_namespace(); - PROTOBUF_NODISCARD std::string* release_csharp_namespace(); + [[nodiscard]] std::string* release_csharp_namespace(); void set_allocated_csharp_namespace(std::string* value); private: @@ -6518,7 +6506,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_swift_prefix(Arg_&& arg, Args_... args); std::string* mutable_swift_prefix(); - PROTOBUF_NODISCARD std::string* release_swift_prefix(); + [[nodiscard]] std::string* release_swift_prefix(); void set_allocated_swift_prefix(std::string* value); private: @@ -6534,7 +6522,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_php_class_prefix(Arg_&& arg, Args_... args); std::string* mutable_php_class_prefix(); - PROTOBUF_NODISCARD std::string* release_php_class_prefix(); + [[nodiscard]] std::string* release_php_class_prefix(); void set_allocated_php_class_prefix(std::string* value); private: @@ -6550,7 +6538,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_php_namespace(Arg_&& arg, Args_... args); std::string* mutable_php_namespace(); - PROTOBUF_NODISCARD std::string* release_php_namespace(); + [[nodiscard]] std::string* release_php_namespace(); void set_allocated_php_namespace(std::string* value); private: @@ -6566,7 +6554,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_php_metadata_namespace(Arg_&& arg, Args_... args); std::string* mutable_php_metadata_namespace(); - PROTOBUF_NODISCARD std::string* release_php_metadata_namespace(); + [[nodiscard]] std::string* release_php_metadata_namespace(); void set_allocated_php_metadata_namespace(std::string* value); private: @@ -6582,7 +6570,7 @@ class PROTOBUF_EXPORT FileOptions final template void set_ruby_package(Arg_&& arg, Args_... args); std::string* mutable_ruby_package(); - PROTOBUF_NODISCARD std::string* release_ruby_package(); + [[nodiscard]] std::string* release_ruby_package(); void set_allocated_ruby_package(std::string* value); private: @@ -6595,7 +6583,7 @@ class PROTOBUF_EXPORT FileOptions final bool has_features() const; void clear_features() ; const ::google::protobuf::FeatureSet& features() const; - PROTOBUF_NODISCARD ::google::protobuf::FeatureSet* release_features(); + [[nodiscard]] ::google::protobuf::FeatureSet* release_features(); ::google::protobuf::FeatureSet* mutable_features(); void set_allocated_features(::google::protobuf::FeatureSet* value); void unsafe_arena_set_allocated_features(::google::protobuf::FeatureSet* value); @@ -6788,11 +6776,9 @@ class PROTOBUF_EXPORT FileOptions final } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + FileOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + FieldOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + ExtensionRangeOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + EnumValueOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + EnumOptions, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -9363,7 +9341,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::OneofOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::OneofOptions* release_options(); + [[nodiscard]] ::google::protobuf::OneofOptions* release_options(); ::google::protobuf::OneofOptions* mutable_options(); void set_allocated_options(::google::protobuf::OneofOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::OneofOptions* value); @@ -9577,7 +9555,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -9593,7 +9571,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final template void set_input_type(Arg_&& arg, Args_... args); std::string* mutable_input_type(); - PROTOBUF_NODISCARD std::string* release_input_type(); + [[nodiscard]] std::string* release_input_type(); void set_allocated_input_type(std::string* value); private: @@ -9609,7 +9587,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final template void set_output_type(Arg_&& arg, Args_... args); std::string* mutable_output_type(); - PROTOBUF_NODISCARD std::string* release_output_type(); + [[nodiscard]] std::string* release_output_type(); void set_allocated_output_type(std::string* value); private: @@ -9622,7 +9600,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::MethodOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::MethodOptions* release_options(); + [[nodiscard]] ::google::protobuf::MethodOptions* release_options(); ::google::protobuf::MethodOptions* mutable_options(); void set_allocated_options(::google::protobuf::MethodOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::MethodOptions* value); @@ -9922,7 +9900,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -9938,7 +9916,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final template void set_extendee(Arg_&& arg, Args_... args); std::string* mutable_extendee(); - PROTOBUF_NODISCARD std::string* release_extendee(); + [[nodiscard]] std::string* release_extendee(); void set_allocated_extendee(std::string* value); private: @@ -9954,7 +9932,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final template void set_type_name(Arg_&& arg, Args_... args); std::string* mutable_type_name(); - PROTOBUF_NODISCARD std::string* release_type_name(); + [[nodiscard]] std::string* release_type_name(); void set_allocated_type_name(std::string* value); private: @@ -9970,7 +9948,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final template void set_default_value(Arg_&& arg, Args_... args); std::string* mutable_default_value(); - PROTOBUF_NODISCARD std::string* release_default_value(); + [[nodiscard]] std::string* release_default_value(); void set_allocated_default_value(std::string* value); private: @@ -9986,7 +9964,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final template void set_json_name(Arg_&& arg, Args_... args); std::string* mutable_json_name(); - PROTOBUF_NODISCARD std::string* release_json_name(); + [[nodiscard]] std::string* release_json_name(); void set_allocated_json_name(std::string* value); private: @@ -9999,7 +9977,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::FieldOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::FieldOptions* release_options(); + [[nodiscard]] ::google::protobuf::FieldOptions* release_options(); ::google::protobuf::FieldOptions* mutable_options(); void set_allocated_options(::google::protobuf::FieldOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::FieldOptions* value); @@ -10274,7 +10252,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -10287,7 +10265,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::EnumValueOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::EnumValueOptions* release_options(); + [[nodiscard]] ::google::protobuf::EnumValueOptions* release_options(); ::google::protobuf::EnumValueOptions* mutable_options(); void set_allocated_options(::google::protobuf::EnumValueOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::EnumValueOptions* value); @@ -10507,7 +10485,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final bool has_options() const; void clear_options() ; const ::google::protobuf::ExtensionRangeOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::ExtensionRangeOptions* release_options(); + [[nodiscard]] ::google::protobuf::ExtensionRangeOptions* release_options(); ::google::protobuf::ExtensionRangeOptions* mutable_options(); void set_allocated_options(::google::protobuf::ExtensionRangeOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::ExtensionRangeOptions* value); @@ -10758,7 +10736,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -10771,7 +10749,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::ServiceOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::ServiceOptions* release_options(); + [[nodiscard]] ::google::protobuf::ServiceOptions* release_options(); ::google::protobuf::ServiceOptions* mutable_options(); void set_allocated_options(::google::protobuf::ServiceOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::ServiceOptions* value); @@ -11042,7 +11020,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -11055,7 +11033,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::EnumOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::EnumOptions* release_options(); + [[nodiscard]] ::google::protobuf::EnumOptions* release_options(); ::google::protobuf::EnumOptions* mutable_options(); void set_allocated_options(::google::protobuf::EnumOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::EnumOptions* value); @@ -11419,7 +11397,7 @@ class PROTOBUF_EXPORT DescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -11432,7 +11410,7 @@ class PROTOBUF_EXPORT DescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::MessageOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::MessageOptions* release_options(); + [[nodiscard]] ::google::protobuf::MessageOptions* release_options(); ::google::protobuf::MessageOptions* mutable_options(); void set_allocated_options(::google::protobuf::MessageOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::MessageOptions* value); @@ -11787,7 +11765,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final template void set_name(Arg_&& arg, Args_... args); std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); + [[nodiscard]] std::string* release_name(); void set_allocated_name(std::string* value); private: @@ -11803,7 +11781,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final template void set_package(Arg_&& arg, Args_... args); std::string* mutable_package(); - PROTOBUF_NODISCARD std::string* release_package(); + [[nodiscard]] std::string* release_package(); void set_allocated_package(std::string* value); private: @@ -11819,7 +11797,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final template void set_syntax(Arg_&& arg, Args_... args); std::string* mutable_syntax(); - PROTOBUF_NODISCARD std::string* release_syntax(); + [[nodiscard]] std::string* release_syntax(); void set_allocated_syntax(std::string* value); private: @@ -11832,7 +11810,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final bool has_options() const; void clear_options() ; const ::google::protobuf::FileOptions& options() const; - PROTOBUF_NODISCARD ::google::protobuf::FileOptions* release_options(); + [[nodiscard]] ::google::protobuf::FileOptions* release_options(); ::google::protobuf::FileOptions* mutable_options(); void set_allocated_options(::google::protobuf::FileOptions* value); void unsafe_arena_set_allocated_options(::google::protobuf::FileOptions* value); @@ -11847,7 +11825,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final bool has_source_code_info() const; void clear_source_code_info() ; const ::google::protobuf::SourceCodeInfo& source_code_info() const; - PROTOBUF_NODISCARD ::google::protobuf::SourceCodeInfo* release_source_code_info(); + [[nodiscard]] ::google::protobuf::SourceCodeInfo* release_source_code_info(); ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); void set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* value); void unsafe_arena_set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* value); @@ -12171,11 +12149,9 @@ class PROTOBUF_EXPORT FileDescriptorSet final } template - PROTOBUF_NODISCARD inline - typename _proto_TypeTraits::Singular::MutableType - ReleaseExtension( - const ::google::protobuf::internal::ExtensionIdentifier& id) { + [[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType + ReleaseExtension(const ::google::protobuf::internal::ExtensionIdentifier< + FileDescriptorSet, _proto_TypeTraits, _field_type, _is_packed>& id) { return _proto_TypeTraits::Release(id.number(), _field_type, &_impl_._extensions_); } template UnsafeArenaSetAllocatedMessage(number, field_type, nullptr, message); } - PROTOBUF_NODISCARD static inline MutableType Release( - int number, FieldType /* field_type */, ExtensionSet* set) { + [[nodiscard]] static inline MutableType Release(int number, + FieldType /* field_type */, + ExtensionSet* set) { return static_cast( set->ReleaseMessage(number, Type::default_instance())); } diff --git a/src/google/protobuf/inlined_string_field.h b/src/google/protobuf/inlined_string_field.h index b4b0ae25b8..ec40008fc5 100644 --- a/src/google/protobuf/inlined_string_field.h +++ b/src/google/protobuf/inlined_string_field.h @@ -199,20 +199,20 @@ class PROTOBUF_EXPORT InlinedStringField { // Own()'d by any arena. If the field is not set, this returns nullptr. The // caller retains ownership. Clears this field back to nullptr state. Used to // implement release_() methods on generated classes. - PROTOBUF_NODISCARD std::string* Release(Arena* arena, bool donated); - PROTOBUF_NODISCARD std::string* Release(); + [[nodiscard]] std::string* Release(Arena* arena, bool donated); + [[nodiscard]] std::string* Release(); // -------------------------------------------------------- // Below functions will be removed in subsequent code change // -------------------------------------------------------- #ifdef DEPRECATED_METHODS_TO_BE_DELETED - PROTOBUF_NODISCARD std::string* Release(const std::string*, Arena* arena, - bool donated) { + [[nodiscard]] std::string* Release(const std::string*, Arena* arena, + bool donated) { return Release(arena, donated); } - PROTOBUF_NODISCARD std::string* ReleaseNonDefault(const std::string*, - Arena* arena) { + [[nodiscard]] std::string* ReleaseNonDefault(const std::string*, + Arena* arena) { return Release(); } diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index dc03435b22..dc1bb518ae 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -659,7 +659,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { // After this it's guaranteed you can safely write kSlopBytes to ptr. This // will never fail! The underlying stream can produce an error. Use HadError // to check for errors. - PROTOBUF_NODISCARD uint8_t* EnsureSpace(uint8_t* ptr) { + [[nodiscard]] uint8_t* EnsureSpace(uint8_t* ptr) { if (PROTOBUF_PREDICT_FALSE(ptr >= end_)) { return EnsureSpaceFallback(ptr); } diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index ee79157d12..bacf97ef43 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -515,8 +515,8 @@ class PROTOBUF_EXPORT Reflection final { void RemoveLast(Message* message, const FieldDescriptor* field) const; // Removes the last element of a repeated message field, and returns the // pointer to the caller. Caller takes ownership of the returned pointer. - PROTOBUF_NODISCARD Message* ReleaseLast(Message* message, - const FieldDescriptor* field) const; + [[nodiscard]] Message* ReleaseLast(Message* message, + const FieldDescriptor* field) const; // Similar to ReleaseLast() without internal safety and ownershp checks. This // method should only be used when the objects are on the same arena or paired @@ -716,7 +716,7 @@ class PROTOBUF_EXPORT Reflection final { // If the field existed (HasField() is true), then the returned pointer will // be the same as the pointer returned by MutableMessage(). // This function has the same effect as ClearField(). - PROTOBUF_NODISCARD Message* ReleaseMessage( + [[nodiscard]] Message* ReleaseMessage( Message* message, const FieldDescriptor* field, MessageFactory* factory = nullptr) const; diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index d96eaa54ca..b8442f9025 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -154,7 +154,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { }; // If return value is negative it's an error - PROTOBUF_NODISCARD LimitToken PushLimit(const char* ptr, int limit) { + [[nodiscard]] LimitToken PushLimit(const char* ptr, int limit) { ABSL_DCHECK(limit >= 0 && limit <= INT_MAX - kSlopBytes); // This add is safe due to the invariant above, because // ptr - buffer_end_ <= kSlopBytes. @@ -165,7 +165,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { return LimitToken(old_limit - limit); } - PROTOBUF_NODISCARD bool PopLimit(LimitToken delta) { + [[nodiscard]] bool PopLimit(LimitToken delta) { // We must update the limit first before the early return. Otherwise, we can // end up with an invalid limit and it can lead to integer overflows. limit_ = limit_ + std::move(delta).token(); @@ -176,14 +176,14 @@ class PROTOBUF_EXPORT EpsCopyInputStream { return true; } - PROTOBUF_NODISCARD const char* Skip(const char* ptr, int size) { + [[nodiscard]] const char* Skip(const char* ptr, int size) { if (size <= BytesAvailable(ptr)) { return ptr + size; } return SkipFallback(ptr, size); } - PROTOBUF_NODISCARD const char* ReadString(const char* ptr, int size, - std::string* s) { + [[nodiscard]] const char* ReadString(const char* ptr, int size, + std::string* s) { if (size <= BytesAvailable(ptr)) { // Fundamentally we just want to do assign to the string. // However micro-benchmarks regress on string reading cases. So we copy @@ -196,8 +196,8 @@ class PROTOBUF_EXPORT EpsCopyInputStream { } return ReadStringFallback(ptr, size, s); } - PROTOBUF_NODISCARD const char* AppendString(const char* ptr, int size, - std::string* s) { + [[nodiscard]] const char* AppendString(const char* ptr, int size, + std::string* s) { if (size <= BytesAvailable(ptr)) { s->append(ptr, size); return ptr + size; @@ -205,12 +205,11 @@ class PROTOBUF_EXPORT EpsCopyInputStream { return AppendStringFallback(ptr, size, s); } // Implemented in arenastring.cc - PROTOBUF_NODISCARD const char* ReadArenaString(const char* ptr, - ArenaStringPtr* s, - Arena* arena); + [[nodiscard]] const char* ReadArenaString(const char* ptr, ArenaStringPtr* s, + Arena* arena); - PROTOBUF_NODISCARD const char* ReadCord(const char* ptr, int size, - ::absl::Cord* cord) { + [[nodiscard]] const char* ReadCord(const char* ptr, int size, + ::absl::Cord* cord) { if (size <= std::min(BytesAvailable(ptr), kMaxCordBytesToCopy)) { *cord = absl::string_view(ptr, size); return ptr + size; @@ -220,20 +219,19 @@ class PROTOBUF_EXPORT EpsCopyInputStream { template - PROTOBUF_NODISCARD const char* ReadRepeatedFixed(const char* ptr, - Tag expected_tag, - RepeatedField* out); + [[nodiscard]] const char* ReadRepeatedFixed(const char* ptr, Tag expected_tag, + RepeatedField* out); template - PROTOBUF_NODISCARD const char* ReadPackedFixed(const char* ptr, int size, - RepeatedField* out); + [[nodiscard]] const char* ReadPackedFixed(const char* ptr, int size, + RepeatedField* out); template - PROTOBUF_NODISCARD const char* ReadPackedVarint(const char* ptr, Add add) { + [[nodiscard]] const char* ReadPackedVarint(const char* ptr, Add add) { return ReadPackedVarint(ptr, add, [](int) {}); } template - PROTOBUF_NODISCARD const char* ReadPackedVarint(const char* ptr, Add add, - SizeCb size_callback); + [[nodiscard]] const char* ReadPackedVarint(const char* ptr, Add add, + SizeCb size_callback); uint32_t LastTag() const { return last_tag_minus_1_ + 1; } bool ConsumeEndGroup(uint32_t start_tag) { @@ -437,8 +435,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { return end; } - PROTOBUF_NODISCARD const char* AppendString(const char* ptr, - std::string* str) { + [[nodiscard]] const char* AppendString(const char* ptr, std::string* str) { return AppendUntilEnd( ptr, [str](const char* p, ptrdiff_t s) { str->append(p, s); }); } @@ -510,15 +507,15 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { // Read the length prefix, push the new limit, call the func(ptr), and then // pop the limit. Useful for situations that don't have an actual message. template - PROTOBUF_NODISCARD const char* ParseLengthDelimitedInlined(const char*, - const Func& func); + [[nodiscard]] const char* ParseLengthDelimitedInlined(const char*, + const Func& func); // Push the recursion depth, call the func(ptr), and then pop depth. Useful // for situations that don't have an actual message. template - PROTOBUF_NODISCARD const char* ParseGroupInlined(const char* ptr, - uint32_t start_tag, - const Func& func); + [[nodiscard]] const char* ParseGroupInlined(const char* ptr, + uint32_t start_tag, + const Func& func); // Use a template to avoid the strong dep into TcParser. All callers will have // the dep. @@ -538,8 +535,9 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { }); } - PROTOBUF_NODISCARD PROTOBUF_NDEBUG_INLINE const char* ParseGroup( - MessageLite* msg, const char* ptr, uint32_t tag) { + [[nodiscard]] PROTOBUF_NDEBUG_INLINE const char* ParseGroup(MessageLite* msg, + const char* ptr, + uint32_t tag) { if (--depth_ < 0) return nullptr; group_depth_++; auto old_depth = depth_; @@ -564,12 +562,12 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { // if (!ptr) return nullptr; // LimitToken old = PushLimit(ptr, size); // if (--depth_ < 0) return nullptr; - PROTOBUF_NODISCARD const char* ReadSizeAndPushLimitAndDepth( - const char* ptr, LimitToken* old_limit); + [[nodiscard]] const char* ReadSizeAndPushLimitAndDepth(const char* ptr, + LimitToken* old_limit); // As above, but fully inlined for the cases where we care about performance // more than size. eg TcParser. - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* + [[nodiscard]] PROTOBUF_ALWAYS_INLINE const char* ReadSizeAndPushLimitAndDepthInlined(const char* ptr, LimitToken* old_limit); // The context keeps an internal stack to keep track of the recursive @@ -877,7 +875,7 @@ static const char* VarintParseSlowArm(const char* p, uint64_t* out, // The caller must ensure that p points to at least 10 valid bytes. template -PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) { +[[nodiscard]] const char* VarintParse(const char* p, T* out) { AssertBytesAreReadable(p, 10); #if defined(__aarch64__) && defined(ABSL_IS_LITTLE_ENDIAN) && !defined(_MSC_VER) // This optimization is not supported in big endian mode @@ -939,13 +937,13 @@ inline const char* ReadTag(const char* p, uint32_t* out, // // Two support routines for ReadTagInlined come first... template -PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE constexpr T RotateLeft( - T x, int s) noexcept { +[[nodiscard]] PROTOBUF_ALWAYS_INLINE constexpr T RotateLeft(T x, + int s) noexcept { return static_cast(x << (s & (std::numeric_limits::digits - 1))) | static_cast(x >> ((-s) & (std::numeric_limits::digits - 1))); } -PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE uint64_t +[[nodiscard]] PROTOBUF_ALWAYS_INLINE uint64_t RotRight7AndReplaceLowByte(uint64_t res, const char& byte) { // TODO: remove the inline assembly #if defined(__x86_64__) && defined(__GNUC__) @@ -1104,7 +1102,7 @@ inline int32_t ReadVarintZigZag32(const char** p) { } template -PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* +[[nodiscard]] PROTOBUF_ALWAYS_INLINE const char* ParseContext::ParseLengthDelimitedInlined(const char* ptr, const Func& func) { LimitToken old; ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); @@ -1118,7 +1116,7 @@ ParseContext::ParseLengthDelimitedInlined(const char* ptr, const Func& func) { } template -PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* +[[nodiscard]] PROTOBUF_ALWAYS_INLINE const char* ParseContext::ParseGroupInlined(const char* ptr, uint32_t start_tag, const Func& func) { if (--depth_ < 0) return nullptr; @@ -1271,12 +1269,12 @@ inline bool VerifyUTF8(const std::string* s, const char* field_name) { } // All the string parsers with or without UTF checking and for all CTypes. -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* InlineGreedyStringParser( +[[nodiscard]] PROTOBUF_EXPORT const char* InlineGreedyStringParser( std::string* s, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD inline const char* InlineCordParser(::absl::Cord* cord, - const char* ptr, - ParseContext* ctx) { +[[nodiscard]] inline const char* InlineCordParser(::absl::Cord* cord, + const char* ptr, + ParseContext* ctx) { int size = ReadSize(&ptr); if (!ptr) return nullptr; return ctx->ReadCord(ptr, size, cord); @@ -1284,8 +1282,8 @@ PROTOBUF_NODISCARD inline const char* InlineCordParser(::absl::Cord* cord, template -PROTOBUF_NODISCARD const char* FieldParser(uint64_t tag, T& field_parser, - const char* ptr, ParseContext* ctx) { +[[nodiscard]] const char* FieldParser(uint64_t tag, T& field_parser, + const char* ptr, ParseContext* ctx) { uint32_t number = tag >> 3; GOOGLE_PROTOBUF_PARSER_ASSERT(number != 0); using WireType = internal::WireFormatLite::WireType; @@ -1330,9 +1328,8 @@ PROTOBUF_NODISCARD const char* FieldParser(uint64_t tag, T& field_parser, } template -PROTOBUF_NODISCARD const char* WireFormatParser(T& field_parser, - const char* ptr, - ParseContext* ctx) { +[[nodiscard]] const char* WireFormatParser(T& field_parser, const char* ptr, + ParseContext* ctx) { while (!ctx->Done(&ptr)) { uint32_t tag; ptr = ReadTag(ptr, &tag); @@ -1351,25 +1348,34 @@ PROTOBUF_NODISCARD const char* WireFormatParser(T& field_parser, // corresponding field // These are packed varints -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedInt32Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedUInt32Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedInt64Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedUInt64Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSInt32Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSInt64Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedEnumParser( - void* object, const char* ptr, ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedInt32Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedUInt32Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedInt64Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedUInt64Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedSInt32Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedSInt64Parser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedEnumParser(void* object, + const char* ptr, + ParseContext* ctx); template -PROTOBUF_NODISCARD const char* PackedEnumParserArg( - void* object, const char* ptr, ParseContext* ctx, Validator validator, - InternalMetadata* metadata, int field_num) { +[[nodiscard]] const char* PackedEnumParserArg(void* object, const char* ptr, + ParseContext* ctx, + Validator validator, + InternalMetadata* metadata, + int field_num) { return ctx->ReadPackedVarint( ptr, [object, validator, metadata, field_num](int32_t val) { if (validator.IsValid(val)) { @@ -1380,28 +1386,31 @@ PROTOBUF_NODISCARD const char* PackedEnumParserArg( }); } -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedBoolParser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFixed32Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSFixed32Parser( - void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFixed64Parser( +[[nodiscard]] PROTOBUF_EXPORT const char* PackedBoolParser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedFixed32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSFixed64Parser( +[[nodiscard]] PROTOBUF_EXPORT const char* PackedSFixed32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFloatParser( +[[nodiscard]] PROTOBUF_EXPORT const char* PackedFixed64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedDoubleParser( +[[nodiscard]] PROTOBUF_EXPORT const char* PackedSFixed64Parser( void* object, const char* ptr, ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedFloatParser(void* object, + const char* ptr, + ParseContext* ctx); +[[nodiscard]] PROTOBUF_EXPORT const char* PackedDoubleParser(void* object, + const char* ptr, + ParseContext* ctx); // This is the only recursive parser. -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownGroupLiteParse( +[[nodiscard]] PROTOBUF_EXPORT const char* UnknownGroupLiteParse( std::string* unknown, const char* ptr, ParseContext* ctx); // This is a helper to for the UnknownGroupLiteParse but is actually also // useful in the generated code. It uses overload on std::string* vs // UnknownFieldSet* to make the generated code isomorphic between full and lite. -PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse( +[[nodiscard]] PROTOBUF_EXPORT const char* UnknownFieldParse( uint32_t tag, std::string* unknown, const char* ptr, ParseContext* ctx); } // namespace internal diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index d1e6183a38..90ab4720ef 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -365,17 +365,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), # define PROTOBUF_PREDICT_FALSE(x) (x) #endif -#ifdef PROTOBUF_NODISCARD -#error PROTOBUF_NODISCARD was previously defined -#endif -#if ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) -#define PROTOBUF_NODISCARD [[nodiscard]] -#elif ABSL_HAVE_ATTRIBUTE(warn_unused_result) || defined(__GNUC__) -#define PROTOBUF_NODISCARD __attribute__((warn_unused_result)) -#else -#define PROTOBUF_NODISCARD -#endif - #ifdef PROTOBUF_RESTRICT #error PROTOBUF_RESTRICT was previously defined #endif diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 784b102d4c..37c3e47c83 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -37,7 +37,6 @@ #undef PROTOBUF_PREDICT_FALSE #undef PROTOBUF_EXPORT #undef PROTOC_EXPORT -#undef PROTOBUF_NODISCARD #undef PROTOBUF_RESTRICT #undef PROTOBUF_UNUSED #undef PROTOBUF_ASSUME diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 15ba502574..57e845e1d8 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -447,7 +447,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } template - PROTOBUF_NODISCARD Value* ReleaseLast() { + [[nodiscard]] Value* ReleaseLast() { Value* result = UnsafeArenaReleaseLast(); // Now perform a copy if we're on an arena. Arena* arena = GetArena(); @@ -1094,7 +1094,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // If this RepeatedPtrField is on an arena, an object copy is required to pass // ownership back to the user (for compatible semantics). Use // UnsafeArenaReleaseLast() if this behavior is undesired. - PROTOBUF_NODISCARD Element* ReleaseLast(); + [[nodiscard]] Element* ReleaseLast(); // Adds an already-allocated object, skipping arena-ownership checks. The user // must guarantee that the given object is in the same arena as this