File tree Expand file tree Collapse file tree
src/google/protobuf/compiler/cpp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -356,7 +356,6 @@ static bool IsEnumMapType(const FieldDescriptor& field) {
356356absl::Status CppGenerator::ValidateFeatures (const FileDescriptor* file) const {
357357 absl::Status status = absl::OkStatus ();
358358 auto edition = GetEdition (*file);
359- absl::string_view filename = file->name ();
360359
361360 google::protobuf::internal::VisitDescriptors (*file, [&](const FieldDescriptor& field) {
362361 const FeatureSet& resolved_features = GetResolvedSourceFeatures (field);
@@ -387,11 +386,7 @@ absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const {
387386 }
388387
389388 if (unresolved_features.has_string_type ()) {
390- if (!CanSkipEditionCheck (filename) && edition < Edition::EDITION_2024) {
391- status = absl::FailedPreconditionError (absl::StrCat (
392- " Field " , field.full_name (),
393- " specifies string_type which is not currently allowed." ));
394- } else if (field.cpp_type () != FieldDescriptor::CPPTYPE_STRING) {
389+ if (field.cpp_type () != FieldDescriptor::CPPTYPE_STRING) {
395390 status = absl::FailedPreconditionError (absl::StrCat (
396391 " Field " , field.full_name (),
397392 " specifies string_type, but is not a string nor bytes field." ));
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumImplicit) {
144144 " Field Foo.bar has a closed enum type with implicit presence." );
145145}
146146
147- TEST_F (CppGeneratorTest, NoStringTypeTillEdition2024 ) {
147+ TEST_F (CppGeneratorTest, AllowStringTypeForEdition2023 ) {
148148 CreateTempFile (" foo.proto" , R"schema(
149149 edition = "2023";
150150 import "google/protobuf/cpp_features.proto";
@@ -155,11 +155,28 @@ TEST_F(CppGeneratorTest, NoStringTypeTillEdition2024) {
155155 }
156156 )schema" );
157157
158+ RunProtoc (
159+ " protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto" );
160+
161+ ExpectNoErrors ();
162+ }
163+
164+ TEST_F (CppGeneratorTest, ErrorsOnBothStringTypeAndCtype) {
165+ CreateTempFile (" foo.proto" , R"schema(
166+ edition = "2023";
167+ import "google/protobuf/cpp_features.proto";
168+
169+ message Foo {
170+ int32 bar = 1;
171+ bytes baz = 2 [ctype = CORD, features.(pb.cpp).string_type = VIEW];
172+ }
173+ )schema" );
174+
158175 RunProtoc (
159176 " protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto" );
160177
161178 ExpectErrorSubstring (
162- " Field Foo.baz specifies string_type which is not currently allowed ." );
179+ " Foo.baz specifies both string_type and ctype which is not supported ." );
163180}
164181
165182TEST_F (CppGeneratorTest, StringTypeForCord) {
You can’t perform that action at this time.
0 commit comments