From 176e5f42b26595256f62d88227261a197b76293e Mon Sep 17 00:00:00 2001 From: Kiro Date: Thu, 2 Jan 2025 09:02:43 +0100 Subject: [PATCH] add Static assert checks --- core/variant/variant.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index f092905a3ab..76657db78a9 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2518,66 +2518,79 @@ Variant::Variant(const ObjectID &p_id) : Variant::Variant(const StringName &p_string) : type(STRING_NAME) { memnew_placement(_data._mem, StringName(p_string)); + static_assert(sizeof(StringName) <= sizeof(_data._mem)); } Variant::Variant(const String &p_string) : type(STRING) { memnew_placement(_data._mem, String(p_string)); + static_assert(sizeof(String) <= sizeof(_data._mem)); } Variant::Variant(const char *const p_cstring) : type(STRING) { memnew_placement(_data._mem, String((const char *)p_cstring)); + static_assert(sizeof(String) <= sizeof(_data._mem)); } Variant::Variant(const char32_t *p_wstring) : type(STRING) { memnew_placement(_data._mem, String(p_wstring)); + static_assert(sizeof(String) <= sizeof(_data._mem)); } Variant::Variant(const Vector3 &p_vector3) : type(VECTOR3) { memnew_placement(_data._mem, Vector3(p_vector3)); + static_assert(sizeof(Vector3) <= sizeof(_data._mem)); } Variant::Variant(const Vector3i &p_vector3i) : type(VECTOR3I) { memnew_placement(_data._mem, Vector3i(p_vector3i)); + static_assert(sizeof(Vector3i) <= sizeof(_data._mem)); } Variant::Variant(const Vector4 &p_vector4) : type(VECTOR4) { memnew_placement(_data._mem, Vector4(p_vector4)); + static_assert(sizeof(Vector4) <= sizeof(_data._mem)); } Variant::Variant(const Vector4i &p_vector4i) : type(VECTOR4I) { memnew_placement(_data._mem, Vector4i(p_vector4i)); + static_assert(sizeof(Vector4i) <= sizeof(_data._mem)); } Variant::Variant(const Vector2 &p_vector2) : type(VECTOR2) { memnew_placement(_data._mem, Vector2(p_vector2)); + static_assert(sizeof(Vector2) <= sizeof(_data._mem)); } Variant::Variant(const Vector2i &p_vector2i) : type(VECTOR2I) { memnew_placement(_data._mem, Vector2i(p_vector2i)); + static_assert(sizeof(Vector2i) <= sizeof(_data._mem)); } Variant::Variant(const Rect2 &p_rect2) : type(RECT2) { memnew_placement(_data._mem, Rect2(p_rect2)); + static_assert(sizeof(Rect2) <= sizeof(_data._mem)); } Variant::Variant(const Rect2i &p_rect2i) : type(RECT2I) { memnew_placement(_data._mem, Rect2i(p_rect2i)); + static_assert(sizeof(Rect2i) <= sizeof(_data._mem)); } Variant::Variant(const Plane &p_plane) : type(PLANE) { memnew_placement(_data._mem, Plane(p_plane)); + static_assert(sizeof(Plane) <= sizeof(_data._mem)); } Variant::Variant(const ::AABB &p_aabb) : @@ -2595,6 +2608,7 @@ Variant::Variant(const Basis &p_matrix) : Variant::Variant(const Quaternion &p_quaternion) : type(QUATERNION) { memnew_placement(_data._mem, Quaternion(p_quaternion)); + static_assert(sizeof(Quaternion) <= sizeof(_data._mem)); } Variant::Variant(const Transform3D &p_transform) : @@ -2618,16 +2632,19 @@ Variant::Variant(const Transform2D &p_transform) : Variant::Variant(const Color &p_color) : type(COLOR) { memnew_placement(_data._mem, Color(p_color)); + static_assert(sizeof(Color) <= sizeof(_data._mem)); } Variant::Variant(const NodePath &p_node_path) : type(NODE_PATH) { memnew_placement(_data._mem, NodePath(p_node_path)); + static_assert(sizeof(NodePath) <= sizeof(_data._mem)); } Variant::Variant(const ::RID &p_rid) : type(RID) { memnew_placement(_data._mem, ::RID(p_rid)); + static_assert(sizeof(::RID) <= sizeof(_data._mem)); } Variant::Variant(const Object *p_object) : @@ -2639,21 +2656,25 @@ Variant::Variant(const Object *p_object) : Variant::Variant(const Callable &p_callable) : type(CALLABLE) { memnew_placement(_data._mem, Callable(p_callable)); + static_assert(sizeof(Callable) <= sizeof(_data._mem)); } Variant::Variant(const Signal &p_callable) : type(SIGNAL) { memnew_placement(_data._mem, Signal(p_callable)); + static_assert(sizeof(Signal) <= sizeof(_data._mem)); } Variant::Variant(const Dictionary &p_dictionary) : type(DICTIONARY) { memnew_placement(_data._mem, Dictionary(p_dictionary)); + static_assert(sizeof(Dictionary) <= sizeof(_data._mem)); } Variant::Variant(const Array &p_array) : type(ARRAY) { memnew_placement(_data._mem, Array(p_array)); + static_assert(sizeof(Array) <= sizeof(_data._mem)); } Variant::Variant(const PackedByteArray &p_byte_array) :