Add an allowlist for implementation reserved fields for the C++ implementation.

This also includes `protoc`.
The allowlist is currently empty.

PiperOrigin-RevId: 493635020
pull/11186/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent e5e2ad866c
commit c6ede6e05a
  1. 9
      src/google/protobuf/descriptor.cc
  2. 1
      src/google/protobuf/descriptor_unittest.cc

@ -5487,6 +5487,12 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
}
}
namespace {
bool IsAllowedReservedField(const FieldDescriptorProto& field) {
return false;
}
} // namespace
void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
Descriptor* parent,
FieldDescriptor* result,
@ -5713,7 +5719,8 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
absl::Substitute("Field numbers cannot be greater than $0.",
FieldDescriptor::kMaxNumber));
} else if (result->number() >= FieldDescriptor::kFirstReservedNumber &&
result->number() <= FieldDescriptor::kLastReservedNumber) {
result->number() <= FieldDescriptor::kLastReservedNumber &&
!IsAllowedReservedField(proto)) {
message_hints_[parent].RequestHintOnFieldNumbers(
proto, DescriptorPool::ErrorCollector::NUMBER);
AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER,

@ -4601,6 +4601,7 @@ TEST_F(ValidationErrorTest, ReservedFieldNumber) {
"foo.proto: Foo: NUMBER: Suggested field numbers for Foo: 1, 2\n");
}
TEST_F(ValidationErrorTest, ExtensionMissingExtendee) {
BuildFileWithErrors(
"name: \"foo.proto\" "

Loading…
Cancel
Save