From 19101826a80b415680738cf3722ee02a0b0c8565 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 13 Jan 2017 18:30:57 -0800 Subject: [PATCH] Fix unused field warning in clang. Change-Id: I71d590a1e5b2709f0e2dcf97faaebda5cb918fc7 Tested: on Linux. --- src/idl_gen_cpp.cpp | 15 +++++++++++++++ tests/monster_test_generated.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index e6b6209be..587bb86af 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1621,6 +1621,11 @@ class CppGenerator : public BaseGenerator { NumToString((*id)++) + "__;"; } + static void PaddingDeclaration(int bits, std::string *code_ptr, int *id) { + (void)bits; + *code_ptr += "(void)padding" + NumToString((*id)++) + "__;"; + } + static void PaddingInitializer(int bits, std::string *code_ptr, int *id) { (void)bits; *code_ptr += ",\n padding" + NumToString((*id)++) + "__(0)"; @@ -1702,10 +1707,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}}"; code_ += " }"; // Generate accessor methods of the form: diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index 82df66e9e..d7c80286c 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -154,6 +154,7 @@ MANUALLY_ALIGNED_STRUCT(2) Test FLATBUFFERS_FINAL_CLASS { : a_(flatbuffers::EndianScalar(_a)), b_(flatbuffers::EndianScalar(_b)), padding0__(0) { + (void)padding0__; } int16_t a() const { return flatbuffers::EndianScalar(a_); @@ -199,6 +200,7 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS { padding1__(0), test3_(_test3), padding2__(0) { + (void)padding0__;(void)padding1__;(void)padding2__; } float x() const { return flatbuffers::EndianScalar(x_);