From 15c8ab5b4fbf412bd8223e51079fa7ee1b5051df Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 13 Feb 2025 20:25:43 +0100 Subject: [PATCH] Base: Constrain size of Base::Type --- src/Base/Type.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Base/Type.cpp b/src/Base/Type.cpp index 6a55ab669b..40ae71e4e0 100644 --- a/src/Base/Type.cpp +++ b/src/Base/Type.cpp @@ -33,6 +33,15 @@ using namespace Base; +static_assert(sizeof(Base::Type) == sizeof(unsigned int), + "Base::Type has been designed to be small to be passed around by value efficiently. " + "The size of Base::Type has changed. Be careful when adding more data members."); + +static_assert( + sizeof(Base::Type) <= 2 * sizeof(void*), + "Base::Type has been designed to be small to be passed around by value efficiently. " + "When the size grows larger than ~2 words, consider passing by const reference instead. " + "Exact limit depends on the architecture and ABI."); struct Base::TypeData {