From 7dd5cfb5103a0aeba126c663fc1ab99ff3a450a0 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 25 Jun 2018 12:26:04 -0700 Subject: [PATCH] Fixed empty structs generating bad constructor. This was fixed previously here: https://github.com/google/flatbuffers/commit/5fd0fefab644caa2bb395cda79fbee6103035818 but somehow got undone in intermediate refactors. Change-Id: I86e45a3f96f67a2b3d84d44081403baef6798921 --- src/idl_gen_cpp.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index c71c15053..6673b14ce 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2497,21 +2497,23 @@ class CppGenerator : public BaseGenerator { } } - code_.SetValue("ARG_LIST", arg_list); - code_.SetValue("INIT_LIST", init_list); - code_ += " {{STRUCT_NAME}}({{ARG_LIST}})"; - code_ += " : {{INIT_LIST}} {"; - padding_id = 0; - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - const auto &field = **it; - if (field.padding) { - std::string padding; - GenPadding(field, &padding, &padding_id, PaddingNoop); - code_ += padding; + if (!arg_list.empty()) { + code_.SetValue("ARG_LIST", arg_list); + code_.SetValue("INIT_LIST", init_list); + code_ += " {{STRUCT_NAME}}({{ARG_LIST}})"; + code_ += " : {{INIT_LIST}} {"; + padding_id = 0; + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const auto &field = **it; + if (field.padding) { + std::string padding; + GenPadding(field, &padding, &padding_id, PaddingNoop); + code_ += padding; + } } + code_ += " }"; } - code_ += " }"; // Generate accessor methods of the form: // type name() const { return flatbuffers::EndianScalar(name_); }