Patch to remove trailing comma from C++ generated enum output

19 views
Skip to first unread message

jaypipes

unread,
Aug 26, 2008, 11:42:57 AM8/26/08
to Protocol Buffers, drizzle...@lists.launchpad.net
Hi!

The C++ code generator has a small bug that produces code that
produces warnings on some compilers when the -pedantic flag is
enabled. In particular, when an enum definition ends in a trailing
comma, a warning is thrown. Here is a patch to fix the small bug.
Thanks,

Jay Pipes
MySQL/Sun

diff -u for /src/google/protobuf/compiler/cpp/cpp_enum.cc:

--- cpp_enum.cc 2008-08-26 10:57:59.000000000 -0400
+++ cpp_enum.cc.bak 2008-08-26 10:58:16.000000000 -0400
@@ -57,7 +57,14 @@
vars["prefix"] = (descriptor_->containing_type() == NULL) ?
"" : classname_ + "_";

- printer->Print(vars, "$prefix$$name$ = $number$,\n");
+ const char* enum_output;
+ // A trailing comma is a pedantic warning on some C++ compilers
+ // and so we ensure that no trailing slash is present
+ if (i != (descriptor_->value_count() - 1))
+ enum_output = "$prefix$$name$ = $number$, \n";
+ else
+ enum_output = "$prefix$$name$ = $number$\n";
+ printer->Print(vars, enum_output);

if (descriptor_->value(i)->number() < min_value->number()) {
min_value = descriptor_->value(i);

Kenton Varda

unread,
Aug 26, 2008, 9:23:47 PM8/26/08
to jaypipes, Protocol Buffers, drizzle...@lists.launchpad.net
Thanks.  I'll apply this after 2.0.1 release, which has been pending for some time blocked on some stupid issue that's out of my hands but should supposedly be resolved any time now.

mordred

unread,
Oct 9, 2008, 2:34:13 PM10/9/08
to Protocol Buffers
Any word on this? It doesn't seem to be in 2.0.2. This is causing us
to commit patched generated files in Drizzle rather than being able to
have just the .proto files.

Thanks!

On Aug 26, 6:23 pm, "Kenton Varda" <ken...@google.com> wrote:
> Thanks.  I'll apply this after 2.0.1 release, which has been pending for
> some time blocked on some stupid issue that's out of my hands but should
> supposedly be resolved any time now.
>

Kenton Varda

unread,
Oct 9, 2008, 3:50:38 PM10/9/08
to mordred, Protocol Buffers
This is fixed in 2.0.2.  I didn't use the exact patch that Jay provided but I made an equivalent change.
Reply all
Reply to author
Forward
0 new messages