Skip to content

Commit b76faa9

Browse files
anandoleecopybara-github
authored andcommitted
Breaking Change: Remove deprecated FieldDescriptor::label() in OSS. Use is_repeated() or is_required() instead
https://protobuf.dev/news/2025-09-19/#cpp-remove-apis PiperOrigin-RevId: 845462045
1 parent 4208121 commit b76faa9

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

editions/generated_files_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ TEST(Generated, RequiredPresence) {
5757
ASSERT_THAT(field, NotNull());
5858
EXPECT_TRUE(field->has_presence());
5959
EXPECT_TRUE(field->is_required());
60-
EXPECT_EQ(field->label(), FieldDescriptor::LABEL_REQUIRED);
6160
}
6261

6362
TEST(Generated, ImplicitPresence) {

python/google/protobuf/pyext/extension_dict.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value) {
197197
return cmessage::ClearFieldByDescriptor(self->parent, descriptor);
198198
}
199199

200-
if (descriptor->label() != FieldDescriptor::LABEL_OPTIONAL ||
200+
if (descriptor->is_repeated() || descriptor->is_required() ||
201201
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
202202
PyErr_SetString(PyExc_TypeError,
203203
"Extension is repeated and/or composite "
@@ -218,7 +218,7 @@ static const FieldDescriptor* FindMessageSetExtension(
218218
if (extension->is_extension() &&
219219
extension->containing_type()->options().message_set_wire_format() &&
220220
extension->type() == FieldDescriptor::TYPE_MESSAGE &&
221-
extension->label() == FieldDescriptor::LABEL_OPTIONAL &&
221+
(!extension->is_repeated() && !extension->is_required()) &&
222222
extension->message_type() == message_descriptor) {
223223
return extension;
224224
}

src/google/protobuf/descriptor.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase,
931931
// Name of the C++ type.
932932
absl::string_view cpp_type_name() const;
933933

934-
// This should never be called directly. Use is_required() and is_repeated()
935-
// helper methods instead.
936-
ABSL_DEPRECATED("Use is_required() or is_repeated() instead.")
937-
Label label() const; // optional/required/repeated
938-
939934
#ifndef SWIG
940935
CppStringType cpp_string_type() const; // The C++ string type of this field.
941936
#endif
@@ -2925,16 +2920,6 @@ inline const Descriptor* FieldDescriptor::extension_scope() const {
29252920
return scope_.extension_scope;
29262921
}
29272922

2928-
inline FieldDescriptor::Label FieldDescriptor::label() const {
2929-
if (is_required()) {
2930-
return LABEL_REQUIRED;
2931-
} else if (is_repeated()) {
2932-
return LABEL_REPEATED;
2933-
} else {
2934-
return LABEL_OPTIONAL;
2935-
}
2936-
}
2937-
29382923
inline FieldDescriptor::Type FieldDescriptor::type() const {
29392924
return static_cast<Type>(type_);
29402925
}

src/google/protobuf/descriptor_unittest.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,11 +1218,6 @@ TEST_F(DescriptorTest, FieldType) {
12181218
}
12191219

12201220
TEST_F(DescriptorTest, FieldLabel) {
1221-
EXPECT_EQ(FieldDescriptor::LABEL_REQUIRED, foo_->label());
1222-
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, bar_->label());
1223-
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, baz_->label());
1224-
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, moo_->label());
1225-
12261221
EXPECT_TRUE(foo_->is_required());
12271222
EXPECT_FALSE((!foo_->is_repeated() && !foo_->is_required()));
12281223
EXPECT_FALSE(foo_->is_repeated());
@@ -2548,10 +2543,12 @@ TEST_F(ExtensionDescriptorTest, Extensions) {
25482543
EXPECT_EQ(moo_, bar_->extension(0)->message_type());
25492544
EXPECT_EQ(moo_, bar_->extension(1)->message_type());
25502545

2551-
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, foo_file_->extension(0)->label());
2552-
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, foo_file_->extension(1)->label());
2553-
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, bar_->extension(0)->label());
2554-
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, bar_->extension(1)->label());
2546+
EXPECT_FALSE(foo_file_->extension(0)->is_required());
2547+
EXPECT_FALSE(foo_file_->extension(0)->is_repeated());
2548+
EXPECT_TRUE(foo_file_->extension(1)->is_repeated());
2549+
EXPECT_FALSE(bar_->extension(0)->is_required());
2550+
EXPECT_FALSE(bar_->extension(0)->is_repeated());
2551+
EXPECT_TRUE(bar_->extension(1)->is_repeated());
25552552

25562553
EXPECT_EQ(foo_, foo_file_->extension(0)->containing_type());
25572554
EXPECT_EQ(foo_, foo_file_->extension(1)->containing_type());
@@ -9637,7 +9634,6 @@ TEST_F(FeaturesTest, RestoresLabelRoundTrip) {
96379634
}
96389635
)pb");
96399636
const FieldDescriptor* field = file->message_type(0)->field(0);
9640-
ASSERT_EQ(field->label(), FieldDescriptor::LABEL_REQUIRED);
96419637
ASSERT_TRUE(field->is_required());
96429638

96439639
FileDescriptorProto proto;

0 commit comments

Comments
 (0)