From: Wouter van Oortmerssen Date: Thu, 19 Jan 2017 00:16:17 +0000 (-0800) Subject: Add no-op for padding variables to prevent clang compiler warning. X-Git-Tag: v1.6.0~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42a265b4198149bfccc5fbde61c0f663c906eeaa;p=platform%2Fupstream%2Fflatbuffers.git Add no-op for padding variables to prevent clang compiler warning. Change-Id: I119ee7109bfa2b0be0f468d2b2be459f45d1bb11 --- diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 329e28a..c21f6b3 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 d7c8028..be20518 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_);