godotengine / godotengine/godot-cpp
Collision on `CONNECT_DEFERRED`
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
4.5
### godot-cpp version
4.5
### System information
Windows 11
### Issue description
The Windows SDK defines `CONNECT_DEFERRED` as a hex value with a preprocessor statement in `winnetwk.h`. However, Godot’s `Object` class uses it as an enum value name inside `ConnectFlags`.
A fix is present inside `godot_cpp/core/defs.hpp`:
`#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum`
The issue is that the header is `#pragma once`, meaning that if `defs.hpp` is ever included before the Windows SDK, the fix stops working because the header can't be included again. In a large codebase, making sure that the right include order is respected everywhere is a very complex task.
A way to make this fix more reliable would be to move the `#undef` statements inside `defs.hpp` to another header that doesn't have a `#pragma once` directive. They are already guarded by `#ifdef` clauses, so this should be okay in theory.
### Steps to reproduce
- Include any Godot header that has `godot_cpp/core/defs.hpp` in its include chain
- Include `Windows.h`
- Include `godot_cpp/core/defs.hpp`
- Try to use `CONNECT_DEFERRED`: Windows's define hasn't been undefined by `defs.hpp`
### Minimal reproduction project
Compile with `scons`, the following errors are thrown:
- 'constant': illegal token on right side of '::'
- type 'unknown-type' unexpected
See `src\example_class.h` for the problematic code and explanation comments.
[GDExample.zip](https://github.com/user-attachments/files/25492175/GDExample.zip)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.