Skip to content

unotify: check return value of TextFormat::PrintToString#270

Merged
robertswiecki merged 1 commit into
google:masterfrom
philwo:fix-unused-result
May 28, 2026
Merged

unotify: check return value of TextFormat::PrintToString#270
robertswiecki merged 1 commit into
google:masterfrom
philwo:fix-unused-result

Conversation

@philwo
Copy link
Copy Markdown
Member

@philwo philwo commented May 26, 2026

The protobuf API marks PrintToString as nodiscard, so ignoring its return value broke the build under -Werror:

unotify/stats.cc: In function ‘void unotify::printStats(nsj_t*)’:
unotify/stats.cc:173:52: error: ignoring return value of ‘static bool google::protobuf::TextFormat::PrintToString(const google::protobuf::Message&, std::string*)’, declared with attribute ‘nodiscard’ [[-Werror=unused-result](https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wno-unused-result)]
  173 |         google::protobuf::TextFormat::PrintToString(report_pb, &text_report);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from unotify/stats.cc:4:
/usr/include/google/protobuf/text_format.h:121:51: note: declared here
  121 |   PROTOBUF_FUTURE_ADD_EARLY_NODISCARD static bool PrintToString(
      |                                                   ^~~~~~~~~~~~~

Check the result and bail out with a warning if formatting fails.

The protobuf API marks PrintToString as nodiscard, so ignoring its
return value broke the build under -Werror=unused-result. Check the
result and bail out with a warning if formatting fails.
@robertswiecki
Copy link
Copy Markdown
Collaborator

Thank you!

@robertswiecki robertswiecki merged commit 1595ebc into google:master May 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants