From 17c4c688e5c9cb97d16a9167204eb56fefd84971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 2 Feb 2026 23:02:21 +0100 Subject: [PATCH] Add expected sizeof test to detect any unwanted growth when refactoring --- test/deque_test.cpp | 3 +++ test/devector_test.cpp | 3 +++ test/list_test.cpp | 3 +++ test/map_test.cpp | 4 ++++ test/set_test.cpp | 4 ++++ test/slist_test.cpp | 3 +++ test/small_vector_test.cpp | 7 +++++-- test/stable_vector_test.cpp | 3 +++ test/static_vector_test.cpp | 4 ++++ test/string_test.cpp | 4 ++++ test/vector_test.cpp | 3 +++ 11 files changed, 39 insertions(+), 2 deletions(-) diff --git a/test/deque_test.cpp b/test/deque_test.cpp index bb697ed..a16f81d 100644 --- a/test/deque_test.cpp +++ b/test/deque_test.cpp @@ -413,6 +413,9 @@ struct alloc_propagate_base }}} //namespace boost::container::test +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(4*sizeof(void*) == sizeof(deque), "sizeof has an unexpected value"); + int main () { if(!do_recursive_deque_test()) diff --git a/test/devector_test.cpp b/test/devector_test.cpp index ad2545d..d719c18 100644 --- a/test/devector_test.cpp +++ b/test/devector_test.cpp @@ -3888,6 +3888,9 @@ int test_cont_variants() return 0; } +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(5*sizeof(void*) == sizeof(devector), "sizeof has an unexpected value"); + int main() { // boost::container::devectora(get()); diff --git a/test/list_test.cpp b/test/list_test.cpp index 0a0d17a..e8077d9 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -160,6 +160,9 @@ struct alloc_propagate_base }}} //namespace boost::container::test +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(3*sizeof(void*) == sizeof(list), "sizeof has an unexpected value"); + int main () { recursive_list_test(); diff --git a/test/map_test.cpp b/test/map_test.cpp index 342fff5..cb0ba23 100644 --- a/test/map_test.cpp +++ b/test/map_test.cpp @@ -386,6 +386,10 @@ bool constructor_template_auto_deduction_test() }}} //namespace boost::container::test +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(4*sizeof(void*) == sizeof(map), "sizeof has an unexpected value"); +BOOST_CONTAINER_STATIC_ASSERT_MSG(4*sizeof(void*) == sizeof(multimap), "sizeof has an unexpected value"); + int main () { using namespace boost::container::test; diff --git a/test/set_test.cpp b/test/set_test.cpp index 30ca493..a91abfa 100644 --- a/test/set_test.cpp +++ b/test/set_test.cpp @@ -379,6 +379,10 @@ void test_merge_from_different_comparison() set1.merge(set2); } +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(4*sizeof(void*) == sizeof(set), "sizeof has an unexpected value"); +BOOST_CONTAINER_STATIC_ASSERT_MSG(4*sizeof(void*) == sizeof(multiset), "sizeof has an unexpected value"); + int main () { using namespace boost::container::test; diff --git a/test/slist_test.cpp b/test/slist_test.cpp index 87543cf..107d25b 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -173,6 +173,9 @@ struct alloc_propagate_base }}} +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(2*sizeof(void*) == sizeof(slist), "sizeof has an unexpected value"); + int main () { recursive_slist_test(); diff --git a/test/small_vector_test.cpp b/test/small_vector_test.cpp index 3567fd1..fbbca92 100644 --- a/test/small_vector_test.cpp +++ b/test/small_vector_test.cpp @@ -468,10 +468,13 @@ int test_cont_variants() return 0; } +using namespace boost::container; + +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(7*sizeof(void*) == sizeof(small_vector), "sizeof has an unexpected value"); + int main() { - using namespace boost::container; - if(!test_swap()) return 1; diff --git a/test/stable_vector_test.cpp b/test/stable_vector_test.cpp index 2565786..b620b9f 100644 --- a/test/stable_vector_test.cpp +++ b/test/stable_vector_test.cpp @@ -104,6 +104,9 @@ struct alloc_propagate_base }}} //namespace boost::container::test +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(5*sizeof(void*) == sizeof(stable_vector), "sizeof has an unexpected value"); + int main() { recursive_vector_test(); diff --git a/test/static_vector_test.cpp b/test/static_vector_test.cpp index bb71ef2..56dc71c 100644 --- a/test/static_vector_test.cpp +++ b/test/static_vector_test.cpp @@ -702,6 +702,10 @@ void static_vector_triviality(){} #endif //BOOST_INTRUSIVE_CONCEPTS_BASED_OVERLOADING +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(5*sizeof(void*) == sizeof(static_vector), "sizeof has an unexpected value"); + + int main(int, char* []) { using boost::container::test::movable_and_copyable_int; diff --git a/test/string_test.cpp b/test/string_test.cpp index 9b3fe40..d5b2280 100644 --- a/test/string_test.cpp +++ b/test/string_test.cpp @@ -2394,6 +2394,10 @@ void test_with_lightweight_test() test_reserve_and_shrink(); } +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(3*sizeof(void*) == sizeof(string), "sizeof has an unexpected value"); + + int main() { if(string_test()){ diff --git a/test/vector_test.cpp b/test/vector_test.cpp index 73e6fa9..21916bd 100644 --- a/test/vector_test.cpp +++ b/test/vector_test.cpp @@ -233,6 +233,9 @@ BOOST_CONTAINER_STATIC_ASSERT_MSG ); #endif +//Test the expected sizeof() +BOOST_CONTAINER_STATIC_ASSERT_MSG(3*sizeof(void*) == sizeof(vector), "sizeof has an unexpected value"); + int main() { {