Skip to content

Commit 68346ec

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: 844846518
1 parent 60f0834 commit 68346ec

2 files changed

Lines changed: 2 additions & 12 deletions

File tree

src/google/protobuf/descriptor.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,7 +3961,8 @@ void FieldDescriptor::DebugString(
39613961

39623962
// Label is omitted for maps, oneof, and plain proto3 fields.
39633963
if (is_map() || real_containing_oneof() ||
3964-
(!is_required() && !is_repeated() && !has_optional_keyword())) {
3964+
(!is_required() && !is_repeated() && !proto3_optional_ &&
3965+
file()->edition() == Edition::EDITION_PROTO3)) {
39653966
label.clear();
39663967
}
39673968
// Label is omitted for optional and required fields under editions.
@@ -4283,12 +4284,6 @@ bool FieldDescriptor::legacy_enum_field_treated_as_closed() const {
42834284
enum_type()->is_closed());
42844285
}
42854286

4286-
bool FieldDescriptor::has_optional_keyword() const {
4287-
return proto3_optional_ ||
4288-
(file()->edition() == Edition::EDITION_PROTO2 && !is_required() &&
4289-
!is_repeated() && !containing_oneof());
4290-
}
4291-
42924287
FieldDescriptor::CppStringType FieldDescriptor::CalculateCppStringType() const {
42934288
ABSL_DCHECK(cpp_type() == FieldDescriptor::CPPTYPE_STRING);
42944289

src/google/protobuf/descriptor.h

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

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

0 commit comments

Comments
 (0)