diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 6bcbdb592..8804c8e8e 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -376,7 +376,16 @@ static void GenStruct(StructDef &struct_def, std::string *code_ptr) { if (field.padding) code += ", __padding" + NumToString(padding_id++) + "(0)"; } - 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; + if (field.padding) + code += " (void)__padding" + NumToString(padding_id++) + ";"; + } + code += " }\n\n"; // Generate accessor methods of the form: // type name() const { return flatbuffers::EndianScalar(name_); } diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index a2a029280..40794f763 100755 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -47,7 +47,7 @@ MANUALLY_ALIGNED_STRUCT(2) Test { public: Test(int16_t a, int8_t b) - : a_(flatbuffers::EndianScalar(a)), b_(flatbuffers::EndianScalar(b)), __padding0(0) {} + : a_(flatbuffers::EndianScalar(a)), b_(flatbuffers::EndianScalar(b)), __padding0(0) { (void)__padding0; } int16_t a() const { return flatbuffers::EndianScalar(a_); } int8_t b() const { return flatbuffers::EndianScalar(b_); } @@ -68,7 +68,7 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 { public: Vec3(float x, float y, float z, double test1, int8_t test2, const Test &test3) - : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)), __padding0(0), test1_(flatbuffers::EndianScalar(test1)), test2_(flatbuffers::EndianScalar(test2)), __padding1(0), test3_(test3), __padding2(0) {} + : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)), __padding0(0), test1_(flatbuffers::EndianScalar(test1)), test2_(flatbuffers::EndianScalar(test2)), __padding1(0), test3_(test3), __padding2(0) { (void)__padding0; (void)__padding1; (void)__padding2; } float x() const { return flatbuffers::EndianScalar(x_); } float y() const { return flatbuffers::EndianScalar(y_); }