aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Silverman <bsilver16384@gmail.com>2015-09-08 18:57:04 -0400
committerBrian Silverman <bsilver16384@gmail.com>2015-09-08 20:25:48 -0400
commit21f3d3777a921eee1cc3fed2eead0cade51eb0f1 (patch)
tree3805aec82a1be5942f4f8c47b2929841df1b8e99 /src
parent133be3dc1f1eb3f3c6252b950e89895469f1193c (diff)
downloadprotobuf-21f3d3777a921eee1cc3fed2eead0cade51eb0f1.tar.gz
protobuf-21f3d3777a921eee1cc3fed2eead0cade51eb0f1.tar.bz2
protobuf-21f3d3777a921eee1cc3fed2eead0cade51eb0f1.zip
Don't assume char is signed.
It isn't always, which causes problems when trying to put negative values into the array with C++11.
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index 5dae4cdd..8e8bd8b7 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -598,8 +598,13 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// bytes in length". Declare a static array of characters rather than use a
// string literal.
if (breakdown_large_file && file_data.size() > 65535) {
+ // This has to be explicitly marked as a signed char because the generated
+ // code puts negative values in the array, and sometimes plain char is
+ // unsigned. That implicit narrowing conversion is not allowed in C++11.
+ // <http://stackoverflow.com/questions/4434140/narrowing-conversions-in-c0x-is-it-just-me-or-does-this-sound-like-a-breakin>
+ // has details on why.
printer->Print(
- "static const char descriptor[] = {\n");
+ "static const signed char descriptor[] = {\n");
printer->Indent();
// Only write 25 bytes per line.