From 9b1d57adf651eec777a617ca7c3d679fed62e662 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 17 Jun 2019 10:22:43 -0400 Subject: [PATCH] I like static_cast --- unit_tests/tests/test_cpp_memory_layout.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unit_tests/tests/test_cpp_memory_layout.cpp b/unit_tests/tests/test_cpp_memory_layout.cpp index 194eeca234..73eef2494c 100644 --- a/unit_tests/tests/test_cpp_memory_layout.cpp +++ b/unit_tests/tests/test_cpp_memory_layout.cpp @@ -70,7 +70,13 @@ TEST(misc, cppVirtualStructMemoryLayout) { memcpy(&destimationInt, &c, 4); ASSERT_NE(540, destimationInt); + // static_cast is smart to skip the vtable, we like static_cast + TestParent *parent = static_cast(&c); + ASSERT_EQ(0, (int)&c.field0 - (int)parent); + ASSERT_EQ(MAGIC_VTABLE_SIZE, (int)&c.field0 - (int)&c); + + } TEST(misc, cppPlainExtraFieldsStructMemoryLayout) {