aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/objectivec
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-04-26 14:40:11 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-04-26 15:15:49 -0400
commit18b6a321b5fd8f53e1029c436c2ad5dd2d3122df (patch)
treed0c0dd00376f74cf985428719766c6fcf2fdbbb5 /src/google/protobuf/compiler/objectivec
parent40574479978f80bd86caf44edae5b0a22d596c79 (diff)
Proper checking of enum with non zero default
proto2 syntax allows the first enum to have a non zero value. This means any field using that default has a non zero default without having an explicit default being set. So when deciding what runtime info is needed, don't rely on an explicit default, always check that the values aren't zero. Fixes https://github.com/google/protobuf/issues/1453
Diffstat (limited to 'src/google/protobuf/compiler/objectivec')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_helpers.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
index fda51807..196b39dd 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -757,10 +757,11 @@ bool HasNonZeroDefaultValue(const FieldDescriptor* field) {
return false;
}
- if (!field->has_default_value()) {
- // No custom default set in the proto file.
- return false;
- }
+ // As much as checking field->has_default_value() seems useful, it isn't
+ // because of enums. proto2 syntax allows the first item in an enum (the
+ // default) to be non zero. So checking field->has_default_value() would
+ // result in missing this non zero default. See MessageWithOneBasedEnum in
+ // objectivec/Tests/unittest_objc.proto for a test Message to confirm this.
// Some proto file set the default to the zero value, so make sure the value
// isn't the zero case.