Deriving from a custom class that implements Godot virtual methods fails to compile #854
Labels
bug
This has been identified as a bug
topic:gdextension
This relates to the new Godot 4 extension implementation
With GodotCpp
master
branch.Simple example:
A setup like this one produces the following compiling errors:
The only workaround I could find so far was to implement those virtual methods again in all derived classes, making them call the parent method. This is inconvenient and becomes a nightmare in cases like this https://github.com/Zylann/godot_voxel/blob/gdextension/editor/vox/vox_scene_importer.h
MRP:
extension_test_issue854_virtual_methods.zip
Note: change the path to GodotCpp in
SConstruct
.It seems to happen because
GDCLASS
internally definesregister_virtuals()
, which callsBaseClass::register_virtuals<CurrentClass>()
. And in there, it does this:When
T
is the derived class, it does not define_ready
. Only its base class does. But for some reason, that makesBIND_VIRTUAL_METHOD
fail to compile.I thought that's because the
if
checks the wrong condition. Indeed, whenT
derives from a custom class,Node::_ready
is not the same function asT::_ready
. ButT
does not actually define_ready
, its custom base class does. So we should not try to bind the method again if it's the same as the base class.So I tried this:
Where
B
is the actual base class, so a more informed check can be done.Unfortunately, the fact there is an
if
does not prevent the code inside from being compiled. The error remains exactly the same: it can't compile the inside of theif
.Here with the macro expanded:
So what I dont understand is, why all the methods I don't override are compiling just fine, while they should be in the same situation?
With
if constexpr
, if the condition doesn't pass, the code inside isn't even compiled. But here it looks like it tries to compile it anyways.Funny enough, if I replace the condition with
It compiles fine. When I try
!std::is_same_v<decltype(&B::_ready), decltype(&T::_ready)>
, I tested and expected it to befalse
too for the derived class, but somehow discarding isn't working.I even tried somthing similar on
https://godbolt.org/
and it worked...The text was updated successfully, but these errors were encountered: