summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2016-12-21 18:04:31 -0800
committerWouter van Oortmerssen <aardappel@gmail.com>2016-12-21 18:04:31 -0800
commit5fd0fefab644caa2bb395cda79fbee6103035818 (patch)
treed07a006d40dcfbc5b0d0239f5420092bd8198f2b
parentb9efbf6a3db61b4b9e0b20fa4a5244218b4c5f19 (diff)
downloadflatbuffers-5fd0fefab644caa2bb395cda79fbee6103035818.tar.gz
flatbuffers-5fd0fefab644caa2bb395cda79fbee6103035818.tar.bz2
flatbuffers-5fd0fefab644caa2bb395cda79fbee6103035818.zip
Fixed empty structs generating illegal constructor in C++.
Change-Id: I60418d597b497c3cfa655ad76b3128351e9139f2
-rw-r--r--src/idl_gen_cpp.cpp63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index 47bf3708..5154b85d 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -1354,39 +1354,40 @@ class CppGenerator : public BaseGenerator {
code += struct_def.name + ")); }\n";
// Generate a constructor that takes all fields as arguments.
- code += " " + struct_def.name + "(";
- 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 += 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 + ")";
+ if (struct_def.fields.vec.size()) {
+ code += " " + struct_def.name + "(";
+ 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 += GenTypeGet(field.value.type, " ", "const ", " &", true);
+ 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 : ";
+ 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 += " }\n\n";
// Generate accessor methods of the form:
// type name() const { return flatbuffers::EndianScalar(name_); }