Skip to content

Commit

Permalink
Add [[deprecated]] attribute when generating enums and classes.
Browse files Browse the repository at this point in the history
When the user adds `option deprecated = true` for an `enum` or `message`, we
should add the `[[deprecated]]` attribute to the generated C++ `enum` or
`class`.

PiperOrigin-RevId: 670583253
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Sep 3, 2024
1 parent c935f72 commit 23aada2
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ci/Linux.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import common.bazelrc

build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion"
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations"
2 changes: 1 addition & 1 deletion ci/macOS.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import common.bazelrc

build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion"
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations"
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
common --xcode_version_config=@com_google_protobuf//.github:host_xcodes
3 changes: 2 additions & 1 deletion src/google/protobuf/compiler/cpp/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ absl::flat_hash_map<absl::string_view, std::string> EnumVars(
const EnumValueDescriptor* min, const EnumValueDescriptor* max) {
auto classname = ClassName(enum_, false);
return {
{"DEPRECATED", enum_->options().deprecated() ? "[[deprecated]]" : ""},
{"Enum", std::string(enum_->name())},
{"Enum_", ResolveKeyword(enum_->name())},
{"Msg_Enum", classname},
Expand Down Expand Up @@ -162,7 +163,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* p) {
}},
},
R"cc(
enum $Msg_Enum_annotated$ : int {
enum $DEPRECATED $$Msg_Enum_annotated$ : int {
$values$,
$open_enum_sentinels$,
};
Expand Down
4 changes: 3 additions & 1 deletion src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ std::vector<Sub> ClassVars(const Descriptor* desc, Options opts) {
{"Msg", ClassName(desc, false)},
{"pkg::Msg", QualifiedClassName(desc, opts)},
{"pkg.Msg", desc->full_name()},
{"deprecated", desc->options().deprecated() ? "[[deprecated]]" : ""},

// Old-style names, to be removed once all usages are gone in this and
// other files.
Expand Down Expand Up @@ -2060,7 +2061,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
)cc");
}}},
R"cc(
class $dllexport_decl $$classname$ final : public $superclass$
class $dllexport_decl $$deprecated $$classname$ final
: public $superclass$
/* @@protoc_insertion_point(class_definition:$full_name$) */ {
public:
inline $classname$() : $classname$(nullptr) {}
Expand Down
3 changes: 2 additions & 1 deletion src/google/protobuf/compiler/java/java_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/google/protobuf/compiler/plugin.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/google/protobuf/cpp_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 23aada2

Please # to comment.