Protobuf: C++ code generator bug: unused parameter in generated files

Created on 13 Aug 2015  Â·  7Comments  Â·  Source: protocolbuffers/protobuf

Hi,
there is a bug in C++ code generator. It creates functions with named arguments, but unused, like:

void Empty::SerializeWithCachedSizes(
    ::google::protobuf::io::CodedOutputStream* output) const {
  // @@protoc_insertion_point(serialize_start:sklik.Empty)
  // @@protoc_insertion_point(serialize_end:sklik.Empty)
}

Example:

$ cat system.proto 
syntax = "proto3";
package sklik;
message Empty {}
service XService {
    rpc Ping1 (Empty) returns (Empty) {}
}
protoc --cpp_out=. system.proto
$ /opt/szn/bin/g++ -std=c++14 -Wall -Wextra -Werror -c -o system.pb.o system.pb.cc
system.pb.cc:200:48: error: unused parameter ‘output’ [-Werror=unused-parameter]
     ::google::protobuf::io::CodedOutputStream* output) const {

Using: protobuf-3.0.0-alpha-3.1

c++ cleanup

All 7 comments

This bug is breaking my -Werror build :(

It seems that implementing a virtual function with a no-op should not generate a compiler warning

@gerben-s Even if it would, it is still a hack and not a fix to this issue. The issue is pretty clear:

In terms of C++ compliance having a named argument that's unused is wrong, no matter what.

Why don't you just fix the generator to generate valid code?

After a year and a half, that's what I call a solution - dismissing the issue... Very disappointing :(

Please cite chapter and verse in the c++11 standard that outlaws unused named arguments as valid c++

Well, if it would be the standard forbidding it, it wouldn't be a warning by definition.

I meant compliance with compilers. Compilers produce a warning and for those who take them seriously with -Werror - it breaks their builds. Isn't that a good enough reason? Especially for a library or a tool generating code.

Re-factor your build such that the protos are organized in a separate lib and compile them without warnings. Compiler warnings are meant to improve and assist human written code. Generated code could just as well be compiled with warnings completely disabled.

Warning in the headers files would be a completely different story.

I believe protobuf team changed their opinion regarding warnings in the generated code. Please continue at https://github.com/protocolbuffers/protobuf/issues/4628#issuecomment-470446302.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sunpoet picture sunpoet  Â·  32Comments

liujisi picture liujisi  Â·  48Comments

cl51287 picture cl51287  Â·  29Comments

kolea2 picture kolea2  Â·  40Comments

blowmage picture blowmage  Â·  26Comments