Skip to content

Collision on CONNECT_DEFERRED #1935

Open

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

Activity

  1. added
    bugThis has been identified as a bug
    on Feb 23, 2026
  2. dsnopek commented on Feb 23, 2026

    @dsnopek
    Collaborator

    Thanks for the report!

    I'm not sure this is something we can fully handle on the godot-cpp side, since godot-cpp isn't the one including windows.h. If someone builds a GDExtension and they are including windows.h, I think the only fully reliable fix is making sure windows.h is included before any godot-cpp headers. We could consider switching defs.hpp back from #pragma once to using header guards (and maybe put the #undef outside of them), but that'll only improve things in a couple situations, not all of them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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