[Bug] Build fails with protobuf 36.1 under -Werror=unused-result

オープン
#623 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cmake, cpp
領域
build-system

調査の方向性

The unused-result errors are at lib/Commands.cc lines 129, 238, 250, 880 and 923, lib/MessageId.cc:87 and lib/ProtobufNativeSchema.cc:49; tests/ProtobufNativeSchemaTest.cc:114 and :123 raise the same warning. Start by reproducing with cmake --build build -- -k against protobuf 36.1. Done means the library compiles under -Werror with protobuf 36.1 because each listed call checks its return value and handles failure, and the MessageTest strncpy failure in #621 is out of scope.

索引モデルが issue の本文から書いたものです。

説明

Search before asking
  • I searched in the issues and found nothing similar.
Version

pulsar-client-cpp 4.2.0 on Arch Linux (x86_64), GCC 16.2.1, protobuf 36.1, abseil-cpp 20260817.0. The same calls are present on main at f71d7e99019d58b1d11858f05ff0dc83b718627b (source inspection; in lib/Commands.cc they are at lines 130, 239, 251, 936 and 979).

Minimal reproduce step

With protobuf 36.1 and the other dependencies installed:

cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_FLAGS=-O2
cmake --build build

The library compilation fails before the test target is built.

What did you expect to see?

The library builds.

What did you see instead?

Diagnostics collected from 4.2.0 with the one-line MessageTest fix proposed in #622 applied, using cmake --build build -- -k (Unix Makefiles generator). The library call sites were unchanged; line numbers below are from 4.2.0.

lib/Commands.cc:129:25: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToArray(void*, int) const', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/Commands.cc:238:25: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToArray(void*, int) const', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/Commands.cc:250:30: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToArray(void*, int) const', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/Commands.cc:880:30: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToArray(void*, int) const', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/Commands.cc:923:28: error: ignoring return value of 'bool google::protobuf::MessageLite::ParseFromArray(const void*, int)', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/MessageId.cc:87:29: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToString(std::string*) const', declared with attribute 'nodiscard' [-Werror=unused-result]
lib/ProtobufNativeSchema.cc:49:39: error: ignoring return value of 'bool google::protobuf::MessageLite::SerializeToArray(void*, int) const', declared with attribute 'nodiscard' [-Werror=unused-result]

With -Wno-error=unused-result, the build also reports the same warnings in tests/ProtobufNativeSchemaTest.cc:114 (SerializeToArray) and :123 (ParseFromArray).

Anything else?

In protobuf 36.1, these methods are annotated [[nodiscard]] (message_lite.h, port_def.inc). The project's -Werror setting turns the unused-result diagnostics at the listed call sites into build errors. The listed call sites do not check the returned success value. Adding -Wno-error=unused-result downgrades these diagnostics to warnings; it does not resolve the separate MessageTest strncpy build failure tracked in #621.

Are you willing to submit a PR?
  • I'm willing to submit a PR!
主要言語
C++
スター
72
フォーク
93
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/pulsar-client-cpp のほかの issue

apache/pulsar-client-cpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。