Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Crash when traversing over items() of temporary json objects #2040

Copy link
Copy link
@BOT-Man-JL

Description

@BOT-Man-JL
Issue body actions
  • What is the issue you have?
  1. crash when traversing over items() of temporary json objects
  2. sometimes got null of pair.value() (https://godbolt.org/z/TTQFHW)
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
  const auto obj = nlohmann::json::parse(R"({
    "key1": 0.1,
    "key2": 0.2
  })");

  auto rvalue = [&]() -> nlohmann::json { return obj; };
  for (const auto& pair : rvalue().items()) {
    std::cout << pair.key() << ": " << pair.value() << "\n";  // crash
  }

  auto crvalue = [&]() -> const nlohmann::json { return obj; };
  for (const auto& pair : crvalue().items()) {
    std::cout << pair.key() << ": " << pair.value() << "\n";  // crash
  }
  • What is the expected behavior?
  1. pair.value() returns 0.1 or 0.2
  2. no crash
  • And what is the actual behavior instead?
  1. crash on my linux machine: json.hpp:14028: void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType&, bool, bool, unsigned int, unsigned int) [with BasicJsonType = nlohmann::basic_json<>]: Assertion ‘false' failed.
  2. pair.value() returns null on Compiler Explorer. (https://godbolt.org/z/TTQFHW)
  1. linux/centos
  2. gcc 6.2
  • Did you use a released version of the library or the version from the develop branch?
  1. latest dev branch
  2. release v3.7.3
Reactions are currently unavailable

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.