From da0a1ac9ba0cddea9e4625212152788f885700b3 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 13 Jun 2022 21:58:21 +0200 Subject: [PATCH] Do compile time checks in compile time instead of tests --- apps/openmw_test_suite/esm/test_fixed_string.cpp | 14 -------------- components/esm/esmcommon.hpp | 9 +++++++++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/openmw_test_suite/esm/test_fixed_string.cpp b/apps/openmw_test_suite/esm/test_fixed_string.cpp index edd5b6bd59..2a3e00d605 100644 --- a/apps/openmw_test_suite/esm/test_fixed_string.cpp +++ b/apps/openmw_test_suite/esm/test_fixed_string.cpp @@ -87,20 +87,6 @@ TEST(EsmFixedString, empty_strings) } } -TEST(EsmFixedString, struct_size) -{ - ASSERT_EQ(4, sizeof(ESM::NAME)); - ASSERT_EQ(32, sizeof(ESM::NAME32)); - ASSERT_EQ(64, sizeof(ESM::NAME64)); -} - -TEST(EsmFixedString, is_pod) -{ - ASSERT_TRUE(std::is_standard_layout_v && std::is_trivial_v); - ASSERT_TRUE(std::is_standard_layout_v && std::is_trivial_v); - ASSERT_TRUE(std::is_standard_layout_v && std::is_trivial_v); -} - TEST(EsmFixedString, assign_should_zero_untouched_bytes_for_4) { ESM::NAME value; diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index 2685371ec0..35c659fb7e 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace ESM { @@ -171,6 +172,14 @@ using NAME = FixedString<4>; using NAME32 = FixedString<32>; using NAME64 = FixedString<64>; +static_assert(std::is_standard_layout_v && std::is_trivial_v); +static_assert(std::is_standard_layout_v && std::is_trivial_v); +static_assert(std::is_standard_layout_v && std::is_trivial_v); + +static_assert(sizeof(NAME) == 4); +static_assert(sizeof(NAME32) == 32); +static_assert(sizeof(NAME64) == 64); + /* This struct defines a file 'context' which can be saved and later restored by an ESMReader instance. It will save the position within a file, and when restored will let you read from that position as