From 93e49decbd6aa202cf17d8a4b648a912f78f3972 Mon Sep 17 00:00:00 2001 From: Akhilesh Arora Date: Thu, 14 May 2026 08:52:39 +0200 Subject: [PATCH] Fix incomplete-type error in set_parents with ordered_json (#5167) When iteration_proxy_value> appears in a context that requires it to be complete (function or lambda parameter), the compiler instantiates basic_json 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 #3732 Signed-off-by: Akhilesh Arora --- include/nlohmann/json.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- tests/src/unit-ordered_json.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index d52c3b06a..f5826191a 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -741,10 +741,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - iterator set_parents(iterator it, typename iterator::difference_type count_set_parents) + iterator set_parents(iterator it, std::ptrdiff_t count_set_parents) { #if JSON_DIAGNOSTICS - for (typename iterator::difference_type i = 0; i < count_set_parents; ++i) + for (std::ptrdiff_t i = 0; i < count_set_parents; ++i) { (it + i)->m_parent = this; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a8da603c7..441b03e09 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21020,10 +21020,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - iterator set_parents(iterator it, typename iterator::difference_type count_set_parents) + iterator set_parents(iterator it, std::ptrdiff_t count_set_parents) { #if JSON_DIAGNOSTICS - for (typename iterator::difference_type i = 0; i < count_set_parents; ++i) + for (std::ptrdiff_t i = 0; i < count_set_parents; ++i) { (it + i)->m_parent = this; } diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index 10bb037bc..63938e60b 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp @@ -69,3 +69,15 @@ TEST_CASE("ordered_json") CHECK(oj1.size() == 4); CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}"); } + +TEST_CASE("regression test for issue #3732 - iteration_proxy_value>") +{ + // Naming the proxy type in a function-parameter position forces eager + // instantiation of basic_json; previously this hit an + // incomplete-type error in set_parents(). + auto fn = [](nlohmann::detail::iteration_proxy_value> const& val) + { + return val.value(); + }; + static_cast(fn); +}