mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +00:00
[C++] Got rid of memset's in constructors (#5938)
* [C++] removed array's memsets from struct parametrized constructor now POD-typed arrays are zero-initialized and class-typed arrays are default-initialized * [C++] memset -> zero/default initialization in default constructor * [C++] Struct-type and array default initialization * [C++] Newly generated tests * [C++] forgotten test * [C++] curly brace by code style * [C++] test if memory is 0's after placement new * [C++] memory leak fix * [C++] simplifying and non-dynamic memory in test * [C++] code cleanup * [C++] disable old-compiler warning * [C++] windows build fix (try) * [C++] debug-new win build fix
This commit is contained in:
@@ -3222,6 +3222,24 @@ void FixedLengthArrayTest() {
|
||||
// Check alignment
|
||||
TEST_EQ(0, reinterpret_cast<uintptr_t>(mArStruct->d()) % 8);
|
||||
TEST_EQ(0, reinterpret_cast<uintptr_t>(mArStruct->f()) % 8);
|
||||
|
||||
// Check if default constructor set all memory zero
|
||||
const size_t arr_size = sizeof(MyGame::Example::ArrayStruct);
|
||||
char non_zero_memory[arr_size];
|
||||
// set memory chunk of size ArrayStruct to 1's
|
||||
std::memset(static_cast<void *>(non_zero_memory), 1, arr_size);
|
||||
// after placement-new it should be all 0's
|
||||
#if defined (_MSC_VER) && defined (_DEBUG)
|
||||
#undef new
|
||||
#endif
|
||||
MyGame::Example::ArrayStruct *ap = new (non_zero_memory) MyGame::Example::ArrayStruct;
|
||||
#if defined (_MSC_VER) && defined (_DEBUG)
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
(void)ap;
|
||||
for (size_t i = 0; i < arr_size; ++i) {
|
||||
TEST_EQ(non_zero_memory[i], 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user