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
Godot version
4.5
godot-cpp version
4.5
System information
Windows 11
Issue description
The Windows SDK defines
CONNECT_DEFERREDas a hex value with a preprocessor statement inwinnetwk.h. However, Godot’sObjectclass uses it as an enum value name insideConnectFlags.A fix is present inside
godot_cpp/core/defs.hpp:#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enumThe issue is that the header is
#pragma once, meaning that ifdefs.hppis 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
#undefstatements insidedefs.hppto another header that doesn't have a#pragma oncedirective. They are already guarded by#ifdefclauses, so this should be okay in theory.Steps to reproduce
godot_cpp/core/defs.hppin its include chainWindows.hgodot_cpp/core/defs.hppCONNECT_DEFERRED: Windows's define hasn't been undefined bydefs.hppMinimal reproduction project
Compile with
scons, the following errors are thrown:See
src\example_class.hfor the problematic code and explanation comments.GDExample.zip