Closed pupil1337 closed 6 months ago
Thanks!
The goal here sounds great: cause a compilation error if trying to register an abstract class with GDREGISTER_CLASS()
(rather than GDREGISTER_ABSTRACT_CLASS()
).
However, I think the implementation here will be confusing for developers (the error they get when using the wrong macros doesn't point to the solution) and for maintainers (my brain has trouble with the !std::is_abstract_v<T> || !is_abstract
condition :-)).
What if we added another static_assert()
to the top of ClassDB::_register_class()
instead?
Something like:
static_assert(std::is_abstract_V<T> && !is_abstract, "Abstract classes must be registered using GDREGISTER_ABSTRACT_CLASS().");
Thanks!
The goal here sounds great: cause a compilation error if trying to register an abstract class with
GDREGISTER_CLASS()
(rather thanGDREGISTER_ABSTRACT_CLASS()
).However, I think the implementation here will be confusing for developers (the error they get when using the wrong macros doesn't point to the solution) and for maintainers (my brain has trouble with the
!std::is_abstract_v<T> || !is_abstract
condition :-)).What if we added another
static_assert()
to the top ofClassDB::_register_class()
instead?Something like:
static_assert(std::is_abstract_V<T> && !is_abstract, "Abstract classes must be registered using GDREGISTER_ABSTRACT_CLASS().");
Thank you for your suggestion, it's very useful! I had change last commit.
Thanks!
Two additional notes:
ClassDB::_register_class()
(with a leading underscore) rather than ClassDB::register_class()
, because otherwise we have this same problem with GDREGISTER_RUNTIME_CLASS()
or GDREGISTER_INTERNAL_CLASS()
.GDREGISTER_CLASS()
) not the function. Despite using the functions directly in the test code (which will be fixed soon by PR https://github.com/godotengine/godot-cpp/pull/1435) we want to encourage developers to use the macros.Congrats on your first merged Godot contribution :tada:
Thanks🌹
Cherry-picked for 4.2 in PR https://github.com/godotengine/godot-cpp/pull/1465
Cherry-picked for 4.1 in PR https://github.com/godotengine/godot-cpp/pull/1466
To Fix #1425
This PR is a resubmission of #1427 , as the repository submitted that time was my master branch it looked bad. So I want to resubmit it.