Fixed empty structs generating illegal constructor in C++.
Change-Id: I60418d597b497c3cfa655ad76b3128351e9139f2
This commit is contained in:
parent
b9efbf6a3d
commit
5fd0fefab6
|
@ -1354,40 +1354,41 @@ class CppGenerator : public BaseGenerator {
|
||||||
code += struct_def.name + ")); }\n";
|
code += struct_def.name + ")); }\n";
|
||||||
|
|
||||||
// Generate a constructor that takes all fields as arguments.
|
// Generate a constructor that takes all fields as arguments.
|
||||||
code += " " + struct_def.name + "(";
|
if (struct_def.fields.vec.size()) {
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
code += " " + struct_def.name + "(";
|
||||||
it != struct_def.fields.vec.end(); ++it) {
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
auto &field = **it;
|
it != struct_def.fields.vec.end(); ++it) {
|
||||||
if (it != struct_def.fields.vec.begin()) code += ", ";
|
auto &field = **it;
|
||||||
code += GenTypeGet(field.value.type, " ", "const ", " &", true);
|
if (it != struct_def.fields.vec.begin()) code += ", ";
|
||||||
code += "_" + field.name;
|
code += GenTypeGet(field.value.type, " ", "const ", " &", true);
|
||||||
}
|
code += "_" + field.name;
|
||||||
code += ")\n : ";
|
|
||||||
padding_id = 0;
|
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
|
||||||
it != struct_def.fields.vec.end(); ++it) {
|
|
||||||
auto &field = **it;
|
|
||||||
if (it != struct_def.fields.vec.begin()) code += ", ";
|
|
||||||
code += field.name + "_(";
|
|
||||||
if (IsScalar(field.value.type.base_type)) {
|
|
||||||
code += "flatbuffers::EndianScalar(";
|
|
||||||
code += GenUnderlyingCast(field, false, "_" + field.name);
|
|
||||||
code += "))";
|
|
||||||
} else {
|
|
||||||
code += "_" + field.name + ")";
|
|
||||||
}
|
}
|
||||||
GenPadding(field, code, padding_id, PaddingInitializer);
|
code += ")\n : ";
|
||||||
|
padding_id = 0;
|
||||||
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
|
it != struct_def.fields.vec.end(); ++it) {
|
||||||
|
auto &field = **it;
|
||||||
|
if (it != struct_def.fields.vec.begin()) code += ", ";
|
||||||
|
code += field.name + "_(";
|
||||||
|
if (IsScalar(field.value.type.base_type)) {
|
||||||
|
code += "flatbuffers::EndianScalar(";
|
||||||
|
code += GenUnderlyingCast(field, false, "_" + field.name);
|
||||||
|
code += "))";
|
||||||
|
} else {
|
||||||
|
code += "_" + field.name + ")";
|
||||||
|
}
|
||||||
|
GenPadding(field, code, padding_id, PaddingInitializer);
|
||||||
|
}
|
||||||
|
code += " {";
|
||||||
|
padding_id = 0;
|
||||||
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
|
it != struct_def.fields.vec.end(); ++it) {
|
||||||
|
auto &field = **it;
|
||||||
|
GenPadding(field, code, padding_id, PaddingDeclaration);
|
||||||
|
}
|
||||||
|
code += " }\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
code += " {";
|
|
||||||
padding_id = 0;
|
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
|
||||||
it != struct_def.fields.vec.end(); ++it) {
|
|
||||||
auto &field = **it;
|
|
||||||
GenPadding(field, code, padding_id, PaddingDeclaration);
|
|
||||||
}
|
|
||||||
code += " }\n\n";
|
|
||||||
|
|
||||||
// Generate accessor methods of the form:
|
// Generate accessor methods of the form:
|
||||||
// type name() const { return flatbuffers::EndianScalar(name_); }
|
// type name() const { return flatbuffers::EndianScalar(name_); }
|
||||||
for (auto it = struct_def.fields.vec.begin();
|
for (auto it = struct_def.fields.vec.begin();
|
||||||
|
|
Loading…
Reference in New Issue