Skip to content

Fix incomplete-type error in set_parents with ordered_json#5167

Merged
nlohmann merged 1 commit into
nlohmann:developfrom
akhilesharora:fix/3732-iter-difference-type
May 14, 2026
Merged

Fix incomplete-type error in set_parents with ordered_json#5167
nlohmann merged 1 commit into
nlohmann:developfrom
akhilesharora:fix/3732-iter-difference-type

Conversation

@akhilesharora

Copy link
Copy Markdown
Contributor

Fixes #3732 (label: confirmed).

If you name detail::iteration_proxy_value<detail::iter_impl<ordered_json>> where it has to be complete (function or lambda parameter), the compile blows up:

error: invalid use of incomplete type
'using ... basic_json<ordered_map>::iterator = ... iter_impl<...>'

The cascade is proxy -> iter_impl<ordered_json> -> basic_json<ordered_map>, and during basic_json's instantiation the compiler hits set_parents(iterator, typename iterator::difference_type) before iterator is complete.

basic_json::difference_type is already std::ptrdiff_t, so just using the underlying type directly avoids the dependent lookup. Same behavior, no ABI change. This was suggested in the issue thread.

Added a regression case in tests/src/unit-ordered_json.cpp (lambda parameter naming the proxy type — same trigger as the minimal repro). Full local ctest run passes (102/102).

The frozen ABI snapshot at tests/abi/include/nlohmann/json_v3_10_5.hpp is intentionally left alone.

When iteration_proxy_value<iter_impl<ordered_json>> appears in a context
that requires it to be complete (function or lambda parameter), the
compiler instantiates basic_json<ordered_map> and walks into

    set_parents(iterator, typename iterator::difference_type)

while iterator is still incomplete, failing with "invalid use of
incomplete type".

basic_json::difference_type is already std::ptrdiff_t, so just naming
the underlying type directly avoids the dependent lookup. Behavior and
ABI are unchanged. This was the approach suggested in the issue thread.

Added a regression case in unit-ordered_json.cpp using the same trigger
pattern (lambda parameter naming the proxy type).

Fixes nlohmann#3732

Signed-off-by: Akhilesh Arora <akhildawra@gmail.com>

@nlohmann nlohmann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann added this to the Release 3.12.1 milestone May 14, 2026
@nlohmann nlohmann merged commit 93e49de into nlohmann:develop May 14, 2026
143 checks passed
@nlohmann

Copy link
Copy Markdown
Owner

Thanks!

GhostVaibhav pushed a commit to GhostVaibhav/json that referenced this pull request May 19, 2026
…5167)

When iteration_proxy_value<iter_impl<ordered_json>> appears in a context
that requires it to be complete (function or lambda parameter), the
compiler instantiates basic_json<ordered_map> and walks into

    set_parents(iterator, typename iterator::difference_type)

while iterator is still incomplete, failing with "invalid use of
incomplete type".

basic_json::difference_type is already std::ptrdiff_t, so just naming
the underlying type directly avoids the dependent lookup. Behavior and
ABI are unchanged. This was the approach suggested in the issue thread.

Added a regression case in unit-ordered_json.cpp using the same trigger
pattern (lambda parameter naming the proxy type).

Fixes nlohmann#3732

Signed-off-by: Akhilesh Arora <akhildawra@gmail.com>
Signed-off-by: Vaibhav Sharma <48472541+GhostVaibhav@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using iteration_proxy_value with ordered_json fails to compile due to incomplete type

2 participants