Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser adds wrapping array when compiled with GCC #3897

Closed
2 tasks done
Jairard opened this issue Dec 23, 2022 · 1 comment
Closed
2 tasks done

Parser adds wrapping array when compiled with GCC #3897

Jairard opened this issue Dec 23, 2022 · 1 comment
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@Jairard
Copy link

Jairard commented Dec 23, 2022

Description

I wrote a simple progam that just read a JSON file, parses it and dumps the result. It appears that the output is not the same when compiled with GCC or Clang, and the GCC executable seems to produce an error: the input JSON is encapsulated in an extraneous array.

Here is a simple makefile to try it (the content of main.cpp is given later):

clang:
	clang++ main.cpp -I . -o clang_parser
gcc:
	g++ main.cpp -I . -o gcc_parser

Reproduction steps

Simply read and parse the following JSON:

[{"id": 1819645}]

Expected vs. actual results

The expected output would be identical to the input:

[{"id": 1819645}]

But I get

[[{"id":1819645}]]

This only occurs using GCC, not with Clang or Clang-cl.

Minimal code example

#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>

int main(void) {
  std::ifstream t("input.json");
  std::stringstream buffer;
  buffer << t.rdbuf();
  std::string str{buffer.str()};

  auto const json{nlohmann::json::parse(str)};
  std::cout << json.dump() << std::endl;

  return 0;
}

Error messages

No response

Compiler and operating system

g++ (GCC) 12.2.0 (occuring) and clang version 14.0.6 (not occuring). OS is 5.13.19-2-MANJARO

Library version

3.11.2

Validation

@nlohmann
Copy link
Owner

See #2583.

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Dec 23, 2022
@nlohmann nlohmann closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead
Projects
None yet
Development

No branches or pull requests

2 participants