Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed some windows warnings #7929

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/flatbuffers/flatbuffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace flatbuffers {
// Converts a Field ID to a virtual table offset.
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
// Should correspond to what EndTable() below builds up.
const int fixed_fields = 2; // Vtable size and Object Size.
return static_cast<voffset_t>((field_id + fixed_fields) * sizeof(voffset_t));
const voffset_t fixed_fields = 2 * sizeof(voffset_t); // Vtable size and Object Size.
return fixed_fields + field_id * sizeof(voffset_t);
}

template<typename T, typename Alloc = std::allocator<T>>
Expand Down Expand Up @@ -360,7 +360,7 @@ class FlatBufferBuilder {
FLATBUFFERS_ASSERT(nested);
// Write the vtable offset, which is the start of any Table.
// We fill its value later.
auto vtableoffsetloc = PushElement<soffset_t>(0);
const uoffset_t vtableoffsetloc = PushElement<soffset_t>(0);
// Write a vtable, which consists entirely of voffset_t elements.
// It starts with the number of offsets, followed by a type id, followed
// by the offsets themselves. In reverse:
Expand Down Expand Up @@ -400,7 +400,7 @@ class FlatBufferBuilder {
auto vt2_size = ReadScalar<voffset_t>(vt2);
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
vt_use = *vt_offset_ptr;
buf_.pop(GetSize() - vtableoffsetloc);
buf_.pop(GetSize() - static_cast<size_t>(vtableoffsetloc));
break;
}
}
Expand Down Expand Up @@ -525,7 +525,7 @@ class FlatBufferBuilder {
FLATBUFFERS_ASSERT(FLATBUFFERS_GENERAL_HEAP_ALLOC_OK);
if (!string_pool)
string_pool = new StringOffsetMap(StringOffsetCompare(buf_));
auto size_before_string = buf_.size();
const size_t size_before_string = buf_.size();
// Must first serialize the string, since the set is all offsets into
// buffer.
auto off = CreateString(str, len);
Expand Down
25 changes: 13 additions & 12 deletions src/idl_gen_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>

#include "flatbuffers/base.h"
#include "flatbuffers/code_generators.h"
Expand Down Expand Up @@ -965,9 +966,9 @@ class CppGenerator : public BaseGenerator {
std::string GetUnionElement(const EnumVal &ev, bool native_type,
const IDLOptions &opts) {
if (ev.union_type.base_type == BASE_TYPE_STRUCT) {
auto name = ev.union_type.struct_def->name;
std::string name = ev.union_type.struct_def->name;
if (native_type) {
name = NativeName(name, ev.union_type.struct_def, opts);
name = NativeName(std::move(name), ev.union_type.struct_def, opts);
}
return WrapInNameSpace(ev.union_type.struct_def->defined_namespace, name);
} else if (IsString(ev.union_type)) {
Expand All @@ -985,8 +986,8 @@ class CppGenerator : public BaseGenerator {
}

std::string UnionVectorVerifySignature(const EnumDef &enum_def) {
auto name = Name(enum_def);
auto type = opts_.scoped_enums ? name : "uint8_t";
const std::string name = Name(enum_def);
const std::string & type = opts_.scoped_enums ? name : "uint8_t";
return "bool Verify" + name + "Vector" +
"(::flatbuffers::Verifier &verifier, " +
"const ::flatbuffers::Vector<::flatbuffers::Offset<void>> "
Expand Down Expand Up @@ -1806,7 +1807,7 @@ class CppGenerator : public BaseGenerator {
field.value.type.element != BASE_TYPE_UTYPE)) {
auto type = GenTypeNative(field.value.type, false, field);
auto cpp_type = field.attributes.Lookup("cpp_type");
auto full_type =
const std::string & full_type =
(cpp_type
? (IsVector(field.value.type)
? "std::vector<" +
Expand Down Expand Up @@ -1953,7 +1954,7 @@ class CppGenerator : public BaseGenerator {
if (!initializer_list.empty()) { initializer_list += ",\n "; }
const auto cpp_type = field->attributes.Lookup("cpp_type");
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
auto type_name = (cpp_type) ? cpp_type->constant
const std::string & type_name = (cpp_type) ? cpp_type->constant
: GenTypeNative(type, /*invector*/ false,
*field, /*forcopy*/ true);
const bool is_ptr = !(IsStruct(type) && field->native_inline) ||
Expand All @@ -1975,7 +1976,7 @@ class CppGenerator : public BaseGenerator {
if (vec_type.base_type == BASE_TYPE_UTYPE) continue;
const auto cpp_type = field->attributes.Lookup("cpp_type");
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
const auto type_name = (cpp_type)
const std::string & type_name = (cpp_type)
? cpp_type->constant
: GenTypeNative(vec_type, /*invector*/ true,
*field, /*forcopy*/ true);
Expand Down Expand Up @@ -2834,7 +2835,7 @@ class CppGenerator : public BaseGenerator {
// Generate code to do force_align for the vector.
if (align > 1) {
const auto vtype = field.value.type.VectorType();
const auto type = IsStruct(vtype) ? WrapInNameSpace(*vtype.struct_def)
const std::string & type = IsStruct(vtype) ? WrapInNameSpace(*vtype.struct_def)
: GenTypeWire(vtype, "", false);
return "_fbb.ForceVectorAlignment(" + field_size + ", sizeof(" + type +
"), " + std::to_string(static_cast<long long>(align)) + ");";
Expand Down Expand Up @@ -3356,7 +3357,7 @@ class CppGenerator : public BaseGenerator {
}
case BASE_TYPE_UTYPE: {
value = StripUnionType(value);
auto type = opts_.scoped_enums ? Name(*field.value.type.enum_def)
const std::string & type = opts_.scoped_enums ? Name(*field.value.type.enum_def)
: "uint8_t";
auto enum_value = "__va->_" + value + "[i].type";
if (!opts_.scoped_enums)
Expand Down Expand Up @@ -3423,7 +3424,7 @@ class CppGenerator : public BaseGenerator {
}
} else {
// _o->field ? CreateT(_fbb, _o->field.get(), _rehasher);
const auto type = field.value.type.struct_def->name;
const std::string & type = field.value.type.struct_def->name;
code += value + " ? Create" + type;
code += "(_fbb, " + value;
if (!field.native_inline) code += GenPtrGet(field);
Expand Down Expand Up @@ -3809,7 +3810,7 @@ class CppGenerator : public BaseGenerator {
const auto field_type = GenTypeGet(type, " ", is_array ? "" : "const ",
is_array ? "" : " &", true);
auto member = Name(*field) + "_";
auto value =
const std::string & value =
is_scalar ? "::flatbuffers::EndianScalar(" + member + ")" : member;

code_.SetValue("FIELD_NAME", Name(*field));
Expand Down Expand Up @@ -3918,7 +3919,7 @@ bool GenerateCPP(const Parser &parser, const std::string &path,
cpp::IDLOptionsCpp opts(parser.opts);
// The '--cpp_std' argument could be extended (like ASAN):
// Example: "flatc --cpp_std c++17:option1:option2".
auto cpp_std = !opts.cpp_std.empty() ? opts.cpp_std : "C++11";
std::string cpp_std = !opts.cpp_std.empty() ? opts.cpp_std : "C++11";
std::transform(cpp_std.begin(), cpp_std.end(), cpp_std.begin(), CharToUpper);
if (cpp_std == "C++0X") {
opts.g_cpp_std = cpp::CPP_STD_X0;
Expand Down
4 changes: 2 additions & 2 deletions tests/monster_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void MutateFlatBuffersTest(uint8_t *flatbuf, std::size_t length) {

// Mutate structs.
auto pos = monster->mutable_pos();
auto test3 = pos->mutable_test3(); // Struct inside a struct.
auto & test3 = pos->mutable_test3(); // Struct inside a struct.
test3.mutate_a(50); // Struct fields never fail.
TEST_EQ(test3.a(), 50);
test3.mutate_a(10);
Expand Down Expand Up @@ -508,7 +508,7 @@ void ObjectFlatBuffersTest(uint8_t *flatbuf) {
CheckMonsterObject(monster2.get());

// Test object copy.
auto monster3 = *monster2;
MonsterT monster3 = *monster2;
flatbuffers::FlatBufferBuilder fbb3;
fbb3.Finish(CreateMonster(fbb3, &monster3, &rehasher), MonsterIdentifier());
const auto len3 = fbb3.GetSize();
Expand Down