From 543fbcdbd9496de9d93a6eb4645640cb47a5514b Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 13 Dec 2023 16:01:51 -0800 Subject: [PATCH] Breaking change: Remove deprecated std::string error collector overrides PiperOrigin-RevId: 590740727 --- src/google/protobuf/compiler/importer.h | 22 ++------------------ src/google/protobuf/descriptor.h | 27 ++----------------------- src/google/protobuf/io/tokenizer.h | 21 ++----------------- src/google/protobuf/retention_test.cc | 17 +++++++++++----- upb/util/def_to_proto_test.h | 6 +++--- 5 files changed, 21 insertions(+), 72 deletions(-) diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h index 539021b8bdd..6bb127a776c 100644 --- a/src/google/protobuf/compiler/importer.h +++ b/src/google/protobuf/compiler/importer.h @@ -181,30 +181,12 @@ class PROTOBUF_EXPORT MultiFileErrorCollector { // Line and column numbers are zero-based. A line number of -1 indicates // an error with the entire file (e.g. "not found"). virtual void RecordError(absl::string_view filename, int line, int column, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(std::string(filename), line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; virtual void RecordWarning(absl::string_view filename, int line, int column, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(std::string(filename), line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } - - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(const std::string& filename, int line, int column, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(const std::string& filename, int line, int column, - const std::string& message) {} }; // Abstract interface which represents a directory tree containing proto files. diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index dfb71df1f29..9b24cb1bb9f 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -2156,12 +2156,8 @@ class PROTOBUF_EXPORT DescriptorPool { virtual void RecordError(absl::string_view filename, absl::string_view element_name, const Message* descriptor, ErrorLocation location, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(std::string(filename), std::string(element_name), descriptor, - location, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; // Reports a warning in the FileDescriptorProto. Use this function if the // problem occurred should NOT interrupt building the FileDescriptorProto. @@ -2176,27 +2172,8 @@ class PROTOBUF_EXPORT DescriptorPool { const Message* descriptor, ErrorLocation location, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(std::string(filename), std::string(element_name), descriptor, - location, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP } - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(const std::string& filename, - const std::string& element_name, - const Message* descriptor, ErrorLocation location, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; - } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(const std::string& filename, - const std::string& element_name, - const Message* descriptor, ErrorLocation location, - const std::string& message) {} }; // Convert the FileDescriptorProto to real descriptors and place them in diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index 0855a17db5b..007d09016eb 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -55,33 +55,16 @@ class PROTOBUF_EXPORT ErrorCollector { // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. virtual void RecordError(int line, ColumnNumber column, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; // Indicates that there was a warning in the input at the given line and // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. virtual void RecordWarning(int line, ColumnNumber column, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP } - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(int line, ColumnNumber column, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; - } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(int line, ColumnNumber column, - const std::string& message) {} }; // This class converts a stream of raw text into a stream of tokens for diff --git a/src/google/protobuf/retention_test.cc b/src/google/protobuf/retention_test.cc index 32b502d1978..8b777699bb7 100644 --- a/src/google/protobuf/retention_test.cc +++ b/src/google/protobuf/retention_test.cc @@ -13,6 +13,7 @@ #include "google/protobuf/descriptor.pb.h" #include +#include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/parser.h" #include "google/protobuf/dynamic_message.h" @@ -160,6 +161,12 @@ TEST(RetentionTest, Method) { .GetExtension(protobuf_unittest::method_option)); } +class SimpleErrorCollector : public io::ErrorCollector { + public: + SimpleErrorCollector() = default; + void RecordError(int line, io::ColumnNumber column, + absl::string_view message) override{}; +}; TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) { // The tests above make assertions against the generated code, but this test @@ -202,7 +209,7 @@ TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor; @@ -242,7 +249,7 @@ TEST(RetentionTest, RemoveEmptyOptions) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor; @@ -282,7 +289,7 @@ TEST(RetentionTest, InvalidDescriptor) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; @@ -331,7 +338,7 @@ TEST(RetentionTest, MissingRequiredField) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; @@ -387,7 +394,7 @@ TEST(RetentionTest, InvalidRecursionDepth) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; diff --git a/upb/util/def_to_proto_test.h b/upb/util/def_to_proto_test.h index fdd102ad053..f8e017cead3 100644 --- a/upb/util/def_to_proto_test.h +++ b/upb/util/def_to_proto_test.h @@ -46,9 +46,9 @@ MATCHER_P(EqualsProtoTreatNansAsEqual, proto, } class NullErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector { - void AddError(const std::string& filename, const std::string& element_name, - const google::protobuf::Message* descriptor, ErrorLocation location, - const std::string& message) override {} + void RecordError(absl::string_view filename, absl::string_view element_name, + const google::protobuf::Message* descriptor, ErrorLocation location, + absl::string_view message) override {} void RecordWarning(absl::string_view filename, absl::string_view element_name, const google::protobuf::Message* descriptor, ErrorLocation location, absl::string_view message) override {}