Skip to content

Commit

Permalink
Use [[nodiscard]] instead of PROTOBUF_NODISCARD
Browse files Browse the repository at this point in the history
With C++17 being baseline, PROTOBUF_NODISCARD is no longer necessary. Directly
using [[nodiscard]] makes port_def.inc smaller.

PiperOrigin-RevId: 693808783
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 6, 2024
1 parent 54b4180 commit 1ceedf8
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 249 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/arenastring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_<field>() 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void SingularString::GenerateAccessorDeclarations(io::Printer* p) const {
template <typename Arg_ = const std::string&, typename... Args_>
$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:
Expand Down
8 changes: 3 additions & 5 deletions src/google/protobuf/compiler/cpp/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,10 @@ class PROTOC_EXPORT Formatter {
Formatter* format_;
};

PROTOBUF_NODISCARD ScopedIndenter ScopedIndent() {
return ScopedIndenter(this);
}
[[nodiscard]] ScopedIndenter ScopedIndent() { return ScopedIndenter(this); }
template <typename... Args>
PROTOBUF_NODISCARD ScopedIndenter ScopedIndent(const char* format,
const Args&&... args) {
[[nodiscard]] ScopedIndenter ScopedIndent(const char* format,
const Args&&... args) {
(*this)(format, static_cast<Args&&>(args)...);
return ScopedIndenter(this);
}
Expand Down
8 changes: 3 additions & 5 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -960,11 +960,9 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
}
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
bool _is_packed>
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$);
Expand Down
16 changes: 8 additions & 8 deletions src/google/protobuf/compiler/plugin.pb.h

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

Loading

0 comments on commit 1ceedf8

Please sign in to comment.