From c638238fae6c7a6d9c544fcec083ccb6ccc263b7 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sat, 26 Aug 2023 17:39:43 +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/object/class_db.h | 3 +++ core/object/object.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/object/class_db.h b/core/object/class_db.h index 3aae3b452e6..57469f03d22 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -187,6 +187,7 @@ public: template static void register_class(bool p_virtual = false) { 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); @@ -201,6 +202,7 @@ public: template static void register_abstract_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); @@ -221,6 +223,7 @@ public: 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/object.h b/core/object/object.h index 318dbf98de7..561e5b8fe3f 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -382,6 +382,7 @@ private: friend class ::ClassDB; \ \ public: \ + typedef m_class self_type; \ static constexpr bool _class_is_enabled = !bool(GD_IS_DEFINED(ClassDB_Disable_##m_class)) && m_inherits::_class_is_enabled; \ virtual String get_class() const override { \ if (_get_extension()) { \ @@ -557,6 +558,8 @@ class ScriptInstance; class Object { public: + typedef Object self_type; + enum ConnectFlags { CONNECT_DEFERRED = 1, CONNECT_PERSIST = 2, // hint for scene to save this connection