Skip to content

Collision on CONNECT_DEFERRED #1935

@RemiPKFX

Description

@RemiPKFX

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis has been identified as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions