Commit 9c0b35cf authored by Bo Yang's avatar Bo Yang

Enusre public header and generated code have no implicit converion.

parent f752d816
......@@ -924,7 +924,7 @@ no_warning_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
../gmock/gtest/lib/libgtest_main.la
no_warning_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include
no_warning_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) \
-Wall -Werror
-Wall -Wconversion -Werror
nodist_no_warning_test_SOURCES = no_warning_test.cc $(protoc_outputs)
TESTS = protobuf-test protobuf-lazy-descriptor-test protobuf-lite-test \
......
......@@ -240,7 +240,7 @@ bool Any::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.Any.type_url"));
} else {
......@@ -291,7 +291,7 @@ void Any::SerializeWithCachedSizes(
// string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Any.type_url");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -316,7 +316,7 @@ void Any::SerializeWithCachedSizes(
// string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Any.type_url");
target =
......
This diff is collapsed.
......@@ -488,7 +488,8 @@ GenerateByteSize(io::Printer* printer) const {
printer->Print(variables_,
"if (data_size > 0) {\n"
" total_size += $tag_size$ +\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(\n"
" static_cast<google::protobuf::int32>(data_size));\n"
"}\n"
"int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n"
"GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
......
......@@ -256,7 +256,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
} else {
printer->Print(variables_,
" unknown_fields_stream.WriteVarint32($tag$u);\n"
" unknown_fields_stream.WriteVarint32(data.size());\n"
" unknown_fields_stream.WriteVarint32(\n"
" static_cast<google::protobuf::uint32>(data.size()));\n"
" unknown_fields_stream.WriteString(data);\n");
}
......@@ -267,12 +268,16 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
if (key_field->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
key_field, options_, true, variables_,
StrCat(key, ".data(), ", key, ".length(),\n").data(), printer);
key_field, options_, true, variables_,
StrCat(key, ".data(), static_cast<int>(", key, ".length()),\n").data(),
printer);
}
if (value_field->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(value_field, options_, true, variables_,
StrCat(value, ".data(), ", value, ".length(),\n").data(), printer);
GenerateUtf8CheckCodeForString(
value_field, options_, true, variables_,
StrCat(value, ".data(), static_cast<int>(", value, ".length()),\n")
.data(),
printer);
}
// If entry is allocated by arena, its desctructor should be avoided.
......@@ -376,14 +381,14 @@ void MapFieldGenerator::GenerateSerializeWithCachedSizes(
printer->Indent();
printer->Indent();
if (string_key) {
GenerateUtf8CheckCodeForString(key_field, options_, false, variables,
"p->first.data(), p->first.length(),\n",
printer);
GenerateUtf8CheckCodeForString(
key_field, options_, false, variables,
"p->first.data(), static_cast<int>(p->first.length()),\n", printer);
}
if (string_value) {
GenerateUtf8CheckCodeForString(value_field, options_, false, variables,
"p->second.data(), p->second.length(),\n",
printer);
GenerateUtf8CheckCodeForString(
value_field, options_, false, variables,
"p->second.data(), static_cast<int>(p->second.length()),\n", printer);
}
printer->Outdent();
printer->Outdent();
......
......@@ -452,7 +452,8 @@ GenerateByteSize(io::Printer* printer) const {
printer->Print(variables_,
"if (data_size > 0) {\n"
" total_size += $tag_size$ +\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(\n"
" static_cast<google::protobuf::int32>(data_size));\n"
"}\n"
"int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n"
"GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
......
......@@ -477,7 +477,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, true, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
"this->$name$().data(), static_cast<int>(this->$name$().length()),\n",
printer);
}
}
......@@ -486,7 +487,8 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, false, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
"this->$name$().data(), static_cast<int>(this->$name$().length()),\n",
printer);
}
printer->Print(variables_,
"::google::protobuf::internal::WireFormatLite::Write$declared_type$MaybeAliased(\n"
......@@ -498,7 +500,8 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, false, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
"this->$name$().data(), static_cast<int>(this->$name$().length()),\n",
printer);
}
printer->Print(variables_,
"target =\n"
......@@ -797,7 +800,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, true, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
"this->$name$().data(), static_cast<int>(this->$name$().length()),\n",
printer);
}
}
......@@ -969,7 +973,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
GenerateUtf8CheckCodeForString(
descriptor_, options_, true, variables_,
"this->$name$(this->$name$_size() - 1).data(),\n"
"this->$name$(this->$name$_size() - 1).length(),\n",
"static_cast<int>(this->$name$(this->$name$_size() - 1).length()),\n",
printer);
}
}
......@@ -982,7 +986,8 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, false, variables_,
"this->$name$(i).data(), this->$name$(i).length(),\n", printer);
"this->$name$(i).data(), static_cast<int>(this->$name$(i).length()),\n",
printer);
}
printer->Outdent();
printer->Print(variables_,
......@@ -999,7 +1004,8 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
descriptor_, options_, false, variables_,
"this->$name$(i).data(), this->$name$(i).length(),\n", printer);
"this->$name$(i).data(), static_cast<int>(this->$name$(i).length()),\n",
printer);
}
printer->Outdent();
printer->Print(variables_,
......
This diff is collapsed.
......@@ -280,7 +280,7 @@ bool FieldAccessInfo::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::PARSE,
"google.protobuf.compiler.FieldAccessInfo.name");
} else {
......@@ -363,7 +363,7 @@ void FieldAccessInfo::SerializeWithCachedSizes(
// optional string name = 1;
if (cached_has_bits & 0x00000001u) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::SERIALIZE,
"google.protobuf.compiler.FieldAccessInfo.name");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -402,7 +402,7 @@ void FieldAccessInfo::SerializeWithCachedSizes(
// optional string name = 1;
if (cached_has_bits & 0x00000001u) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::SERIALIZE,
"google.protobuf.compiler.FieldAccessInfo.name");
target =
......@@ -795,7 +795,7 @@ bool MessageAccessInfo::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::PARSE,
"google.protobuf.compiler.MessageAccessInfo.name");
} else {
......@@ -862,7 +862,7 @@ void MessageAccessInfo::SerializeWithCachedSizes(
// optional string name = 1;
if (cached_has_bits & 0x00000001u) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::SERIALIZE,
"google.protobuf.compiler.MessageAccessInfo.name");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -897,7 +897,7 @@ void MessageAccessInfo::SerializeWithCachedSizes(
// optional string name = 1;
if (cached_has_bits & 0x00000001u) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->name().data(), this->name().length(),
this->name().data(), static_cast<int>(this->name().length()),
::google::protobuf::internal::WireFormat::SERIALIZE,
"google.protobuf.compiler.MessageAccessInfo.name");
target =
......
This diff is collapsed.
......@@ -213,7 +213,7 @@ bool FieldMask::MergePartialFromCodedStream(
input, this->add_paths()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(this->paths_size() - 1).data(),
this->paths(this->paths_size() - 1).length(),
static_cast<int>(this->paths(this->paths_size() - 1).length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.FieldMask.paths"));
} else {
......@@ -252,7 +252,7 @@ void FieldMask::SerializeWithCachedSizes(
// repeated string paths = 1;
for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
this->paths(i).data(), static_cast<int>(this->paths(i).length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.FieldMask.paths");
::google::protobuf::internal::WireFormatLite::WriteString(
......@@ -271,7 +271,7 @@ void FieldMask::SerializeWithCachedSizes(
// repeated string paths = 1;
for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
this->paths(i).data(), static_cast<int>(this->paths(i).length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.FieldMask.paths");
target = ::google::protobuf::internal::WireFormatLite::
......
......@@ -150,7 +150,8 @@ struct ReflectionSchema {
}
uint32 GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
return oneof_case_offset_ + (oneof_descriptor->index() * sizeof(uint32));
return oneof_case_offset_ +
static_cast<uint32>(oneof_descriptor->index() * sizeof(uint32));
}
bool HasHasbits() const { return has_bits_offset_ != -1; }
......
......@@ -250,11 +250,11 @@ class MapEntryImpl : public Base {
int GetCachedSize() const {
int size = 0;
size += has_key()
? kTagSize + KeyTypeHandler::GetCachedSize(key())
? static_cast<int>(kTagSize + KeyTypeHandler::GetCachedSize(key()))
: 0;
size += has_value()
? kTagSize + ValueTypeHandler::GetCachedSize(
value())
? static_cast<int>(kTagSize + ValueTypeHandler::GetCachedSize(
value()))
: 0;
return size;
}
......
......@@ -168,7 +168,7 @@ template <typename Derived, typename Key, typename T,
int MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::size() const {
MapFieldBase::SyncMapWithRepeatedField();
return impl_.GetMap().size();
return static_cast<int>(impl_.GetMap().size());
}
template <typename Derived, typename Key, typename T,
......
......@@ -60,7 +60,7 @@ class MapFieldLite {
Map<Key, T>* MutableMap() { return &map_; }
// Convenient methods for generated message implementation.
int size() const { return map_.size(); }
int size() const { return static_cast<int>(map_.size()); }
void Clear() { return map_.clear(); }
void MergeFrom(const MapFieldLite& other) {
for (typename Map<Key, T>::const_iterator it = other.map_.begin();
......
......@@ -284,7 +284,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize(
template <typename Type> \
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \
const MapEntryAccessorType& value) { \
return WireFormatLite::DeclaredType##Size(value); \
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
}
GOOGLE_PROTOBUF_BYTE_SIZE(STRING, String)
......@@ -320,7 +320,8 @@ template <typename Type>
inline int
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize(
const MapEntryAccessorType& value) {
return WireFormatLite::LengthDelimitedSize(value.GetCachedSize());
return static_cast<int>(
WireFormatLite::LengthDelimitedSize(value.GetCachedSize()));
}
#define GET_CACHED_SIZE(FieldType, DeclaredType) \
......@@ -328,7 +329,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize(
inline int \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \
const MapEntryAccessorType& value) { \
return WireFormatLite::DeclaredType##Size(value); \
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
}
GET_CACHED_SIZE(STRING, String)
......
......@@ -218,7 +218,7 @@ bool SourceContext::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.SourceContext.file_name"));
} else {
......@@ -257,7 +257,7 @@ void SourceContext::SerializeWithCachedSizes(
// string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.SourceContext.file_name");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -276,7 +276,7 @@ void SourceContext::SerializeWithCachedSizes(
// string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.SourceContext.file_name");
target =
......
......@@ -340,7 +340,7 @@ bool Struct::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, &parser));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
parser.key().data(), parser.key().length(),
parser.key().data(), static_cast<int>(parser.key().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.Struct.FieldsEntry.key"));
} else {
......@@ -385,7 +385,7 @@ void Struct::SerializeWithCachedSizes(
struct Utf8Check {
static void Check(ConstPtr p) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
p->first.data(), p->first.length(),
p->first.data(), static_cast<int>(p->first.length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Struct.FieldsEntry.key");
}
......@@ -449,7 +449,7 @@ void Struct::SerializeWithCachedSizes(
struct Utf8Check {
static void Check(ConstPtr p) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
p->first.data(), p->first.length(),
p->first.data(), static_cast<int>(p->first.length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Struct.FieldsEntry.key");
}
......@@ -834,7 +834,7 @@ bool Value::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_string_value()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->string_value().data(), this->string_value().length(),
this->string_value().data(), static_cast<int>(this->string_value().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.Value.string_value"));
} else {
......@@ -923,7 +923,7 @@ void Value::SerializeWithCachedSizes(
// string string_value = 3;
if (has_string_value()) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->string_value().data(), this->string_value().length(),
this->string_value().data(), static_cast<int>(this->string_value().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Value.string_value");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -970,7 +970,7 @@ void Value::SerializeWithCachedSizes(
// string string_value = 3;
if (has_string_value()) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->string_value().data(), this->string_value().length(),
this->string_value().data(), static_cast<int>(this->string_value().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Value.string_value");
target =
......
This diff is collapsed.
......@@ -268,7 +268,7 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
if (size > 0) {
const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer);
// The number of bytes each type occupies on the wire.
const int per_value_size = tag_size + sizeof(value);
const int per_value_size = tag_size + static_cast<int>(sizeof(value));
// parentheses around (std::min) prevents macro expansion of min(...)
int elements_available =
......@@ -344,8 +344,8 @@ inline bool WireFormatLite::ReadPackedFixedSizePrimitive(
int length;
if (!input->ReadVarintSizeAsInt(&length)) return false;
const int old_entries = values->size();
const int new_entries = length / sizeof(CType);
const int new_bytes = new_entries * sizeof(CType);
const int new_entries = length / static_cast<int>(sizeof(CType));
const int new_bytes = new_entries * static_cast<int>(sizeof(CType));
if (new_bytes != length) return false;
// We would *like* to pre-allocate the buffer to write into (for
// speed), but *must* avoid performing a very large allocation due
......@@ -695,7 +695,7 @@ inline uint8* WireFormatLite::WriteFixedNoTagToArray(
GOOGLE_DCHECK_GT(n, 0);
const T* ii = value.unsafe_data();
const int bytes = n * sizeof(ii[0]);
const int bytes = n * static_cast<int>(sizeof(ii[0]));
memcpy(target, ii, bytes);
return target + bytes;
#else
......
......@@ -2209,7 +2209,7 @@ bool StringValue::MergePartialFromCodedStream(
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_value()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->value().data(), this->value().length(),
this->value().data(), static_cast<int>(this->value().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.StringValue.value"));
} else {
......@@ -2248,7 +2248,7 @@ void StringValue::SerializeWithCachedSizes(
// string value = 1;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->value().data(), this->value().length(),
this->value().data(), static_cast<int>(this->value().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.StringValue.value");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
......@@ -2267,7 +2267,7 @@ void StringValue::SerializeWithCachedSizes(
// string value = 1;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->value().data(), this->value().length(),
this->value().data(), static_cast<int>(this->value().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.StringValue.value");
target =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment