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.
pull/6661/head
EFanZh 5 years ago
parent b9f405ae46
commit ad713fe342
  1. 8
      src/google/protobuf/compiler/cpp/cpp_message.cc

@ -1030,7 +1030,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format(
" static bool ValidateKey(std::string* s) {\n"
" 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"
" }\n",
descriptor_->field(0)->full_name());
@ -1040,7 +1040,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" static bool ValidateKey(std::string* s) {\n"
"#ifndef NDEBUG\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"
"#endif\n"
" return true;\n"
@ -1056,7 +1056,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format(
" static bool ValidateValue(std::string* s) {\n"
" 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"
" }\n",
descriptor_->field(1)->full_name());
@ -1066,7 +1066,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" static bool ValidateValue(std::string* s) {\n"
"#ifndef NDEBUG\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"
"#endif\n"
" return true;\n"

Loading…
Cancel
Save