From a06fd84b758379b663c2f8b7f884d8a746dcc0f9 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 6 Jan 2025 14:22:43 +0100 Subject: [PATCH] util/construct_at.h: ensure legit sizeof(Placeable) If the memory for the designated object is allocated as char[sizeof(T)], the size of 'Placeable' is expected to equal the size of T. However, in principle, the compiler has the freedom to inflate the 'Placeable' object. The static assertion gives us the assurance that the compiler does not violate our assumption. --- repos/base/include/util/construct_at.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repos/base/include/util/construct_at.h b/repos/base/include/util/construct_at.h index 20387900c9..9282d62376 100644 --- a/repos/base/include/util/construct_at.h +++ b/repos/base/include/util/construct_at.h @@ -72,6 +72,8 @@ static inline T * Genode::construct_at(void *at, ARGS &&... args) } }; + static_assert(sizeof(Placeable) == sizeof(T)); + /* * If the args input to this function contains rvalues, the compiler would * use the according rvalue references as lvalues at the following call if