Commit 2e865f4d authored by Laurent Stacul's avatar Laurent Stacul Committed by Wouter van Oortmerssen

[Fix #5112] flatc generates constructors with memset for non-trivial types (#5222)

parent 13c9c674
......@@ -166,7 +166,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
public:
Vec3() {
memset(this, 0, sizeof(Vec3));
memset(static_cast<void *>(this), 0, sizeof(Vec3));
}
Vec3(float _x, float _y, float _z)
: x_(flatbuffers::EndianScalar(_x)),
......
......@@ -2617,7 +2617,7 @@ class CppGenerator : public BaseGenerator {
// Generate a default constructor.
code_ += " {{STRUCT_NAME}}() {";
code_ += " memset(this, 0, sizeof({{STRUCT_NAME}}));";
code_ += " memset(static_cast<void *>(this), 0, sizeof({{STRUCT_NAME}}));";
code_ += " }";
// Generate a constructor that takes all fields as arguments.
......
......@@ -516,7 +516,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(2) Test FLATBUFFERS_FINAL_CLASS {
public:
Test() {
memset(this, 0, sizeof(Test));
memset(static_cast<void *>(this), 0, sizeof(Test));
}
Test(int16_t _a, int8_t _b)
: a_(flatbuffers::EndianScalar(_a)),
......@@ -559,7 +559,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Vec3 FLATBUFFERS_FINAL_CLASS {
public:
Vec3() {
memset(this, 0, sizeof(Vec3));
memset(static_cast<void *>(this), 0, sizeof(Vec3));
}
Vec3(float _x, float _y, float _z, double _test1, Color _test2, const Test &_test3)
: x_(flatbuffers::EndianScalar(_x)),
......@@ -631,7 +631,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
public:
Ability() {
memset(this, 0, sizeof(Ability));
memset(static_cast<void *>(this), 0, sizeof(Ability));
}
Ability(uint32_t _id, uint32_t _distance)
: id_(flatbuffers::EndianScalar(_id)),
......
......@@ -57,7 +57,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) StructInNestedNS FLATBUFFERS_FINAL_CLASS
public:
StructInNestedNS() {
memset(this, 0, sizeof(StructInNestedNS));
memset(static_cast<void *>(this), 0, sizeof(StructInNestedNS));
}
StructInNestedNS(int32_t _a, int32_t _b)
: a_(flatbuffers::EndianScalar(_a)),
......
......@@ -189,7 +189,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Rapunzel FLATBUFFERS_FINAL_CLASS {
public:
Rapunzel() {
memset(this, 0, sizeof(Rapunzel));
memset(static_cast<void *>(this), 0, sizeof(Rapunzel));
}
Rapunzel(int32_t _hair_length)
: hair_length_(flatbuffers::EndianScalar(_hair_length)) {
......@@ -214,7 +214,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) BookReader FLATBUFFERS_FINAL_CLASS {
public:
BookReader() {
memset(this, 0, sizeof(BookReader));
memset(static_cast<void *>(this), 0, sizeof(BookReader));
}
BookReader(int32_t _books_read)
: books_read_(flatbuffers::EndianScalar(_books_read)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment