diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2016-03-02 10:16:20 -0800 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2016-03-02 10:16:20 -0800 |
commit | 78105897a8f01c7be9cf8502b6c58d47eb1ccdd7 (patch) | |
tree | 34ef5261b48e243e031d5e2d2eacb738a82283eb /src/google/protobuf | |
parent | 584233bd043a80b2172a598039113d4fe14dc326 (diff) | |
parent | b3d802d21534e97e571e0afa36c68323353e260d (diff) | |
download | protobuf-78105897a8f01c7be9cf8502b6c58d47eb1ccdd7.tar.gz protobuf-78105897a8f01c7be9cf8502b6c58d47eb1ccdd7.tar.bz2 protobuf-78105897a8f01c7be9cf8502b6c58d47eb1ccdd7.zip |
Merge pull request #1260 from legrosbuffle/master
Make cpp generated enum constants constexpr when Options::proto_h is specified
Diffstat (limited to 'src/google/protobuf')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_enum.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 1a11bce8..5ee6f000 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -178,12 +178,13 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) { map<string, string> vars; vars["nested_name"] = descriptor_->name(); vars["classname"] = classname_; + vars["constexpr"] = options_.proto_h ? "constexpr " : ""; printer->Print(vars, "typedef $classname$ $nested_name$;\n"); for (int j = 0; j < descriptor_->value_count(); j++) { vars["tag"] = EnumValueName(descriptor_->value(j)); printer->Print(vars, - "static const $nested_name$ $tag$ = $classname$_$tag$;\n"); + "static $constexpr$const $nested_name$ $tag$ = $classname$_$tag$;\n"); } printer->Print(vars, @@ -237,6 +238,7 @@ void EnumGenerator::GenerateDescriptorInitializer( void EnumGenerator::GenerateMethods(io::Printer* printer) { map<string, string> vars; vars["classname"] = classname_; + vars["constexpr"] = options_.proto_h ? "constexpr " : ""; if (HasDescriptorMethods(descriptor_->file())) { printer->Print(vars, @@ -287,7 +289,7 @@ void EnumGenerator::GenerateMethods(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { vars["value"] = EnumValueName(descriptor_->value(i)); printer->Print(vars, - "const $classname$ $parent$::$value$;\n"); + "$constexpr$const $classname$ $parent$::$value$;\n"); } printer->Print(vars, "const $classname$ $parent$::$nested_name$_MIN;\n" |