Browse Source

Cast size_t type to int type explicitly

Currently, the generated header file might cause warnings if user specifies `-Wconversion` compiler option. This commit should be able to fix it.
EFanZh 6 years ago
parent
commit
a4301ca6eb
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/google/protobuf/compiler/cpp/cpp_message.cc

+ 4 - 4
src/google/protobuf/compiler/cpp/cpp_message.cc

@@ -1030,7 +1030,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
         format(
         format(
             "  static bool ValidateKey(std::string* s) {\n"
             "  static bool ValidateKey(std::string* s) {\n"
             "    return ::$proto_ns$::internal::WireFormatLite::"
             "    return ::$proto_ns$::internal::WireFormatLite::"
-            "VerifyUtf8String(s->data(), s->size(), "
+            "VerifyUtf8String(s->data(), static_cast<int>(s->size()), "
             "::$proto_ns$::internal::WireFormatLite::PARSE, \"$1$\");\n"
             "::$proto_ns$::internal::WireFormatLite::PARSE, \"$1$\");\n"
             " }\n",
             " }\n",
             descriptor_->field(0)->full_name());
             descriptor_->field(0)->full_name());
@@ -1040,7 +1040,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
             "  static bool ValidateKey(std::string* s) {\n"
             "  static bool ValidateKey(std::string* s) {\n"
             "#ifndef NDEBUG\n"
             "#ifndef NDEBUG\n"
             "    ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n"
             "    ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n"
-            "       s->data(), s->size(), ::$proto_ns$::internal::"
+            "       s->data(), static_cast<int>(s->size()), ::$proto_ns$::internal::"
             "WireFormatLite::PARSE, \"$1$\");\n"
             "WireFormatLite::PARSE, \"$1$\");\n"
             "#endif\n"
             "#endif\n"
             "    return true;\n"
             "    return true;\n"
@@ -1056,7 +1056,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
         format(
         format(
             "  static bool ValidateValue(std::string* s) {\n"
             "  static bool ValidateValue(std::string* s) {\n"
             "    return ::$proto_ns$::internal::WireFormatLite::"
             "    return ::$proto_ns$::internal::WireFormatLite::"
-            "VerifyUtf8String(s->data(), s->size(), "
+            "VerifyUtf8String(s->data(), static_cast<int>(s->size()), "
             "::$proto_ns$::internal::WireFormatLite::PARSE, \"$1$\");\n"
             "::$proto_ns$::internal::WireFormatLite::PARSE, \"$1$\");\n"
             " }\n",
             " }\n",
             descriptor_->field(1)->full_name());
             descriptor_->field(1)->full_name());
@@ -1066,7 +1066,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
             "  static bool ValidateValue(std::string* s) {\n"
             "  static bool ValidateValue(std::string* s) {\n"
             "#ifndef NDEBUG\n"
             "#ifndef NDEBUG\n"
             "    ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n"
             "    ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n"
-            "       s->data(), s->size(), ::$proto_ns$::internal::"
+            "       s->data(), static_cast<int>(s->size()), ::$proto_ns$::internal::"
             "WireFormatLite::PARSE, \"$1$\");\n"
             "WireFormatLite::PARSE, \"$1$\");\n"
             "#endif\n"
             "#endif\n"
             "    return true;\n"
             "    return true;\n"