Skip to content

Commit 1ceedf8

Browse files
Use [[nodiscard]] instead of PROTOBUF_NODISCARD
With C++17 being baseline, PROTOBUF_NODISCARD is no longer necessary. Directly using [[nodiscard]] makes port_def.inc smaller. PiperOrigin-RevId: 693808783
1 parent 54b4180 commit 1ceedf8

File tree

15 files changed

+219
-249
lines changed

15 files changed

+219
-249
lines changed

src/google/protobuf/arenastring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
344344
// Own()'d by any arena. If the field is not set, this returns nullptr. The
345345
// caller retains ownership. Clears this field back to the default state.
346346
// Used to implement release_<field>() methods on generated classes.
347-
PROTOBUF_NODISCARD std::string* Release();
347+
[[nodiscard]] std::string* Release();
348348

349349
// Takes a std::string that is heap-allocated, and takes ownership. The
350350
// std::string's destructor is registered with the arena. Used to implement

src/google/protobuf/compiler/cpp/field_generators/message_field.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void SingularMessage::GenerateAccessorDeclarations(io::Printer* p) const {
164164

165165
p->Emit(R"cc(
166166
$DEPRECATED$ const $Submsg$& $name$() const;
167-
$DEPRECATED$ PROTOBUF_NODISCARD $Submsg$* $release_name$();
167+
$DEPRECATED$ [[nodiscard]] $Submsg$* $release_name$();
168168
$DEPRECATED$ $Submsg$* $mutable_name$();
169169
$DEPRECATED$ void $set_allocated_name$($Submsg$* value);
170170
$DEPRECATED$ void $unsafe_arena_set_allocated_name$($Submsg$* value);

src/google/protobuf/compiler/cpp/field_generators/string_field.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void SingularString::GenerateAccessorDeclarations(io::Printer* p) const {
270270
template <typename Arg_ = const std::string&, typename... Args_>
271271
$DEPRECATED$ void $set_name$(Arg_&& arg, Args_... args);
272272
$DEPRECATED$ std::string* $mutable_name$();
273-
$DEPRECATED$ PROTOBUF_NODISCARD std::string* $release_name$();
273+
$DEPRECATED$ [[nodiscard]] std::string* $release_name$();
274274
$DEPRECATED$ void $set_allocated_name$(std::string* value);
275275
276276
private:

src/google/protobuf/compiler/cpp/helpers.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,10 @@ class PROTOC_EXPORT Formatter {
939939
Formatter* format_;
940940
};
941941

942-
PROTOBUF_NODISCARD ScopedIndenter ScopedIndent() {
943-
return ScopedIndenter(this);
944-
}
942+
[[nodiscard]] ScopedIndenter ScopedIndent() { return ScopedIndenter(this); }
945943
template <typename... Args>
946-
PROTOBUF_NODISCARD ScopedIndenter ScopedIndent(const char* format,
947-
const Args&&... args) {
944+
[[nodiscard]] ScopedIndenter ScopedIndent(const char* format,
945+
const Args&&... args) {
948946
(*this)(format, static_cast<Args&&>(args)...);
949947
return ScopedIndenter(this);
950948
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,9 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
960960
}
961961
template <typename _proto_TypeTraits, $pbi$::FieldType _field_type,
962962
bool _is_packed>
963-
PROTOBUF_NODISCARD inline
964-
typename _proto_TypeTraits::Singular::MutableType
965-
ReleaseExtension(
966-
const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits,
967-
_field_type, _is_packed>& id) {
963+
[[nodiscard]] inline typename _proto_TypeTraits::Singular::MutableType
964+
ReleaseExtension(const $pbi$::ExtensionIdentifier<
965+
$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) {
968966
$WeakDescriptorSelfPin$;
969967
$annotate_extension_release$;
970968
return _proto_TypeTraits::Release(id.number(), _field_type, &$extensions$);

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

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)