Protobuf: Build warning when compiling protobuf generated file with clang

Created on 5 Sep 2019  ·  1Comment  ·  Source: protocolbuffers/protobuf

When compiling a very simple message generated with protoc 3.9.0 I'm getting the following warning with clang compiler. The issue is new and did not appear with protoc 3.7.0.

*.pb.cc:84:147: error: possible misuse of comma operator here [-Werror,-Wcomma]
static bool dynamic_init_dummy_printerevent_2eproto = ( ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_printerevent_2eproto), true);
^
*.pb.cc:84:58: note: cast expression to void to silence warning
static bool dynamic_init_dummy_printerevent_2eproto = ( ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_printerevent_2eproto), true);
^~~~~~~~~~~~~~~~~~~~~
static_cast( )
1 error generated.

Most helpful comment

Issue still exists in protobuc 3.9.1:

~/Desktop/tests/protobuf-comma
❯ cat test.proto 
syntax = "proto3";

message Test {
   string dummy = 1;
}
~/Desktop/tests/protobuf-comma
❯ protoc --version                            
libprotoc 3.9.1



md5-9e6148eae547761ddebac9868e7c582d



~/Desktop/tests/protobuf-comma
❯ protoc --cpp_out=. --proto_path=. test.proto



md5-9e6148eae547761ddebac9868e7c582d



~/Desktop/tests/protobuf-comma
❯ clang++ --shared --std=c++17 -Wcomma -l protobuf test.pb.cc
test.pb.cc:75:131: warning: possible misuse of comma operator here [-Wcomma]
static bool dynamic_init_dummy_test_2eproto = (  ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_test_2eproto), true);
                                                                                                                                  ^
test.pb.cc:75:50: note: cast expression to void to silence warning
static bool dynamic_init_dummy_test_2eproto = (  ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_test_2eproto), true);
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                 static_cast<void>(                                                               )
1 warning generated.

>All comments

Issue still exists in protobuc 3.9.1:

~/Desktop/tests/protobuf-comma
❯ cat test.proto 
syntax = "proto3";

message Test {
   string dummy = 1;
}
~/Desktop/tests/protobuf-comma
❯ protoc --version                            
libprotoc 3.9.1



md5-9e6148eae547761ddebac9868e7c582d



~/Desktop/tests/protobuf-comma
❯ protoc --cpp_out=. --proto_path=. test.proto



md5-9e6148eae547761ddebac9868e7c582d



~/Desktop/tests/protobuf-comma
❯ clang++ --shared --std=c++17 -Wcomma -l protobuf test.pb.cc
test.pb.cc:75:131: warning: possible misuse of comma operator here [-Wcomma]
static bool dynamic_init_dummy_test_2eproto = (  ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_test_2eproto), true);
                                                                                                                                  ^
test.pb.cc:75:50: note: cast expression to void to silence warning
static bool dynamic_init_dummy_test_2eproto = (  ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_test_2eproto), true);
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                 static_cast<void>(                                                               )
1 warning generated.

Was this page helpful?
0 / 5 - 0 ratings