Skip to content

Do not use Qt's keyword macros as identifiers - #5866

Open
nlohmann wants to merge 2 commits into
developfrom
fix/qt-slots-5865
Open

nlohmann wants to merge 2 commits into
developfrom
fix/qt-slots-5865

Conversation

@nlohmann

Copy link
Copy Markdown
Owner

Fixes #5865.

#5836 added a prefix_tree member named slots. Qt defines slots as an empty macro (unless QT_NO_KEYWORDS is set), so including any Qt header before json.hpp failed to compile. This PR:

  • renames the member to table (include/nlohmann/detail/json_pointer.hpp, re-amalgamated),
  • adds tests/src/unit-qt_keywords.cpp, which defines Qt's keyword macros as Qt does (slots, signals, emit, foreach, forever) before including the library and exercises parsing, dumping, flatten/unflatten, JSON pointers, the binary formats, and patch/diff. With the old header, this test fails to compile with the same errors as in the issue,
  • lists the check in the quality-assurance docs, next to the <Windows.h> check.

The bug only exists on develop since #5836 and is not in any release.

Breaking changes

None. The renamed member belongs to an internal detail type.

🤖 Generated with Claude Code

The prefix tree used by unflatten() (#5836) had a member named slots, which
Qt defines as an empty macro, so including a Qt header before this library
failed to compile. Rename it to table and add a test that includes the
library with Qt's keyword macros (slots, signals, emit, foreach, forever)
defined.

Fixes #5865

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann nlohmann added this to the Release 3.13.0 milestone Oct 17, 2026
@nlohmann nlohmann added the 🚀 ready to merge Ready to merge - just waiting for CI to complete. label Oct 17, 2026
Clang (-Werror) rejected the macros that the test defines but the library
must not use, and clang-tidy asked for parentheses around the arguments
of the Q_FOREACH imitation, where the variable is a declaration.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

This branch has not been deployed

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

Labels

documentation L 🚀 ready to merge Ready to merge - just waiting for CI to complete. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prefix_tree::slots collides with Qt’s slots macro

1 participant