1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
From 2e865f4d4e67a9b628c137aab7da8140dd9339a4 Mon Sep 17 00:00:00 2001
From: Laurent Stacul <laurent.stacul@gmail.com>
Date: Mon, 4 Mar 2019 20:10:18 +0100
Subject: [PATCH] [Fix #5112] flatc generates constructors with memset for
non-trivial types (#5222)
---
samples/monster_generated.h | 2 +-
src/idl_gen_cpp.cpp | 2 +-
tests/monster_test_generated.h | 6 +++---
tests/namespace_test/namespace_test1_generated.h | 2 +-
tests/union_vector/union_vector_generated.h | 4 ++--
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/samples/monster_generated.h b/samples/monster_generated.h
index db79c2e5d..5286ffd80 100644
--- a/samples/monster_generated.h
+++ b/samples/monster_generated.h
@@ -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)),
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index a25dd6f94..efbfe07c6 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -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.
diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h
index 9154439eb..f8c82f528 100644
--- a/tests/monster_test_generated.h
+++ b/tests/monster_test_generated.h
@@ -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)),
diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h
index 3f964b090..d26bf43e8 100644
--- a/tests/namespace_test/namespace_test1_generated.h
+++ b/tests/namespace_test/namespace_test1_generated.h
@@ -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)),
diff --git a/tests/union_vector/union_vector_generated.h b/tests/union_vector/union_vector_generated.h
index f085bbcb6..8629d4edf 100644
--- a/tests/union_vector/union_vector_generated.h
+++ b/tests/union_vector/union_vector_generated.h
@@ -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)) {
|