godotengine / godotengine/godot
Cannot declare virtual method with enum from own class
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
v4.4.dev7
v4.3.stable
v4.2.2.stable
v4.1.stable
### System information
Windows 11 24H2
### Issue description
Attempting to setup a class which defines a virtual method for an enum setup in that class. That is, before `VARIANT_ENUM_CAST` gets setup. Because the logic in the virtual method is declared immediately, any generic calls are established before this crucial step. In this case, it's `PtrToArg` that's setup too early.
### Steps to reproduce
Script excerpt:
```cpp
class Logger : public RefCounted {
GDCLASS(Logger, RefCounted);
protected:
static void _bind_methods();
public:
enum class LogLevel {
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
MAX,
};
virtual void log(const String &p_content, LogLevel p_level, const TypedDictionary &p_context = {}) = 0;
#define _COMMA ,
GDVIRTUAL3(_log, String, LogLevel, TypedDictionary);
#undef _COMMA
};
VARIANT_ENUM_CAST(Logger::LogLevel);
```
Error output:
```
Use of undeclared identifier 'argval2'; did you mean 'argval1'? clang(undeclared_var_use_suggest)
Expected ';' after expression clang(expected_semi_after_expr)
No member named 'EncodeT' in 'PtrToArg' clang(no_member)
Use of undeclared identifier 'argval2' clang(undeclared_var_use)
Implicit instantiation of undefined template 'GetTypeInfo' clang(template_instantiate_undefined)
type_info.h(62, 8): Template is declared here
```
### Minimal reproduction project (MRP)
N/A
Contributor guide
Research direction
Start by examining the GDVIRTUAL3 declaration and the VARIANT_ENUM_CAST setup in the reproduction, then trace the related PtrToArg and GetTypeInfo instantiations, including type_info.h. Confirm the failure with the listed Godot versions and clang diagnostics. Done means the Logger example can declare its virtual enum method without these template or generated-code errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100