Skip to content

json becomes empty for unknown reason #2470

@congard

Description

@congard

It is a really strange issue: when I pass nlohmann::json to function it (json) becomes empty for an unknown reason. Moreover, if I just copy this function and rename it, everything ok.

Code below uses glm. It is in a separate header that is included in others.

template<typename T>
T import(const nlohmann::json &config) {
    if (config.empty()) // true
        return T();

    T glmType;
    auto array = reinterpret_cast<typename T::value_type *>(&glmType);

    for (glm::length_t i = 0; i < sizeof(T) / sizeof(array[0]); i++)
        array[i] = config[i];

    return glmType;
}

Example:

json pos = {1, 2, 3};
assert(!pos.empty());
vec3 m_pos = import<vec3>(pos); // returns empty vector, but if I copy & rename function 'import' - everything will be ok

What is the expected behavior?

config mustn't be empty

And what is the actual behavior instead?

config for unknown reason becomes empty

Which compiler and operating system are you using?

  • Compiler: GCC 10.2.0 / Clang 10.0.1
  • Operating system: Linux (ArchLinux)

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions