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

Abierto
#623 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cmake, cpp
Área
build-system

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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!
Lenguaje dominante
C++
Estrellas
72
Forks
93
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/pulsar-client-cpp

Todos los issues de apache/pulsar-client-cpp

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.