Skip to content

Using iteration_proxy_value with ordered_json fails to compile due to incomplete type #3732

@falbrechtskirchinger

Description

@falbrechtskirchinger

Description

Using iteration_proxy_value with ordered_json as shown below fails to compile due to an incomplete type error in iterator set_parents(iterator it, typename iterator::difference_type count_set_parents).

The error can be avoided by altering the order of template instantiation by either forcing instantiation (undesirable; increases compile time for everyone) or rewriting set_parents() without iterator::difference_type.

Users facing this issue may force instantiation in the correct order using

using ItemType = decltype(*std::declval<nlohmann::ordered_json>().items().begin());

before code triggering the compilation failure.

(Found via #3731.)

Reproduction steps

See code example.

Expected vs. actual results

Code should compile.

Minimal code example

void test(nlohmann::detail::iteration_proxy_value<
          nlohmann::detail::iter_impl<nlohmann::ordered_json>> const& val) {
    static_cast<void>(val.value());
}

Error messages

GCC:

error: invalid use of incomplete type 'using nlohmann::json_abi_v3_11_2::basic_json<nlohmann::json_abi_v3_11_2::ordered_map>::iterator = nlohmann::json_abi_v3_11_2::basic_json<nlohmann::json_abi_v3_11_2::ordered_map>::iter_impl<nlohmann::json_abi_v3_11_2::basic_json<nlohmann::json_abi_v3_11_2::ordered_map> >' {aka 'class nlohmann::json_abi_v3_11_2::detail::iter_impl<nlohmann::json_abi_v3_11_2::basic_json<nlohmann::json_abi_v3_11_2::ordered_map> >'}

Clang:

error: no type named 'difference_type' in 'nlohmann::detail::iter_impl<nlohmann::basic_json<nlohmann::ordered_map>>'

MSVC:

error C2039: 'difference_type': is not a member of 'nlohmann::json_abi_v3_11_2::detail::iter_impl<nlohmann::json_abi_v3_11_2::ordered_json>'

Compiler and operating system

Compiler Explorer: GCC (trunk) / Clang (trunk) / MSVC latest

Library version

3.11.2/develop

Validation

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions