From 42a265b4198149bfccc5fbde61c0f663c906eeaa Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen <aardappel@gmail.com> Date: Wed, 18 Jan 2017 16:16:17 -0800 Subject: [PATCH] Add no-op for padding variables to prevent clang compiler warning. Change-Id: I119ee7109bfa2b0be0f468d2b2be459f45d1bb11 --- src/idl_gen_cpp.cpp | 28 ++++++++++++++-------------- tests/monster_test_generated.h | 4 +++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 329e28a2..c21f6b31 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1618,14 +1618,14 @@ class CppGenerator : public BaseGenerator { NumToString((*id)++) + "__;"; } - static void PaddingDeclaration(int bits, std::string *code_ptr, int *id) { + static void PaddingInitializer(int bits, std::string *code_ptr, int *id) { (void)bits; - *code_ptr += "(void)padding" + NumToString((*id)++) + "__;"; + *code_ptr += ",\n padding" + NumToString((*id)++) + "__(0)"; } - static void PaddingInitializer(int bits, std::string *code_ptr, int *id) { + static void PaddingNoop(int bits, std::string *code_ptr, int *id) { (void)bits; - *code_ptr += ",\n padding" + NumToString((*id)++) + "__(0)"; + *code_ptr += " (void)padding" + NumToString((*id)++) + "__;"; } // Generate an accessor struct with constructor for a flatbuffers struct. @@ -1704,20 +1704,20 @@ class CppGenerator : public BaseGenerator { } } - padding_id = 0; - std::string padding_list; - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto field = *it; - GenPadding(*field, &padding_list, &padding_id, PaddingDeclaration); - } - code_.SetValue("ARG_LIST", arg_list); code_.SetValue("INIT_LIST", init_list); - code_.SetValue("PADDING_LIST", padding_list); code_ += " {{STRUCT_NAME}}({{ARG_LIST}})"; code_ += " : {{INIT_LIST}} {"; - if (padding_list.length()) code_ += " {{PADDING_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_ += " }"; // Generate accessor methods of the form: diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index d7c80286..be205181 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -200,7 +200,9 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS { padding1__(0), test3_(_test3), padding2__(0) { - (void)padding0__;(void)padding1__;(void)padding2__; + (void)padding0__; + (void)padding1__; + (void)padding2__; } float x() const { return flatbuffers::EndianScalar(x_); -- GitLab