From 4b205afd3dd890cf26d03ebe9f2d58c91161ef73 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sun, 27 Aug 2023 16:22:01 +0200 Subject: [PATCH] Add check to ensure registered classes are declared Checks that all classes registered to `ClassDB` have been properly declared with `GDCLASS` --- core/class_db.h | 3 +++ core/object.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/class_db.h b/core/class_db.h index 0fcef8b8d412..82bcb8da25df 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -170,6 +170,7 @@ class ClassDB { template static void register_class() { GLOBAL_LOCK_FUNCTION; + static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); ERR_FAIL_COND(!t); @@ -182,6 +183,7 @@ class ClassDB { template static void register_virtual_class() { GLOBAL_LOCK_FUNCTION; + static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); ERR_FAIL_COND(!t); @@ -198,6 +200,7 @@ class ClassDB { template static void register_custom_instance_class() { GLOBAL_LOCK_FUNCTION; + static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); ERR_FAIL_COND(!t); diff --git a/core/object.h b/core/object.h index 161cdd456cc0..1653d8c3b0da 100644 --- a/core/object.h +++ b/core/object.h @@ -269,6 +269,7 @@ private: friend class ClassDB; \ \ public: \ + typedef m_class self_type; \ virtual String get_class() const { \ return String(#m_class); \ } \ @@ -407,6 +408,8 @@ class ObjectRC; class Object { public: + typedef Object self_type; + enum ConnectFlags { CONNECT_DEFERRED = 1,