Skip to content

Commit 901729e

Browse files
anandoleecopybara-github
authored andcommitted
Breaking Change: Remove deprecated FieldDescriptor::has_optional_keyword() in OSS. Use is_repeated() or has_presence() instead
https://protobuf.dev/news/2025-09-19/#cpp-remove-apis PiperOrigin-RevId: 843293774
1 parent 3839268 commit 901729e

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

src/google/protobuf/descriptor.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ void FieldDescriptor::DebugString(
39573957

39583958
// Label is omitted for maps, oneof, and plain proto3 fields.
39593959
if (is_map() || real_containing_oneof() ||
3960-
(!is_required() && !is_repeated() && !has_optional_keyword())) {
3960+
(!is_required() && !is_repeated() && !has_presence())) {
39613961
label.clear();
39623962
}
39633963
// Label is omitted for optional and required fields under editions.
@@ -4279,12 +4279,6 @@ bool FieldDescriptor::legacy_enum_field_treated_as_closed() const {
42794279
enum_type()->is_closed());
42804280
}
42814281

4282-
bool FieldDescriptor::has_optional_keyword() const {
4283-
return proto3_optional_ ||
4284-
(file()->edition() == Edition::EDITION_PROTO2 && !is_required() &&
4285-
!is_repeated() && !containing_oneof());
4286-
}
4287-
42884282
FieldDescriptor::CppStringType FieldDescriptor::CalculateCppStringType() const {
42894283
ABSL_DCHECK(cpp_type() == FieldDescriptor::CPPTYPE_STRING);
42904284

src/google/protobuf/descriptor.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase,
11351135
int legacy_proto_ctype() const { return legacy_proto_ctype_; }
11361136
bool has_legacy_proto_ctype() const;
11371137

1138-
// Returns true if this field was syntactically written with "optional" in the
1139-
// .proto file. Excludes singular proto3 fields that do not have a label.
1140-
ABSL_DEPRECATED("Use has_presence() instead.")
1141-
bool has_optional_keyword() const;
1142-
11431138
// Get the merged features that apply to this field. These are specified in
11441139
// the .proto file through the feature options in the message definition.
11451140
// Allowed features are defined by Features in descriptor.proto, along with

0 commit comments

Comments
 (0)