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

Strange behaviour when creating array with single element #3025

Closed
1 of 5 tasks
misos1 opened this issue Sep 21, 2021 · 1 comment
Closed
1 of 5 tasks

Strange behaviour when creating array with single element #3025

misos1 opened this issue Sep 21, 2021 · 1 comment
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@misos1
Copy link

misos1 commented Sep 21, 2021

What is the issue you have?

Seems when calling a function which takes an argument of type json with {j} where j is of type json then is called a copy constructor instead of basic_json(initializer_list_t init....

Please describe the steps to reproduce the issue.

  1. See example below

Can you provide a small but working code example?

void func(json j)
{
	printf("%s\n", j.dump().c_str());
}

int main()
{
	json j = 10;
	func({j, j});
	func({10});
	func({j});
}

What is the expected behavior?

func({j}); should print "[10]".

And what is the actual behavior instead?

func({j}); prints "10".

[10,10]
[10]
10

Which compiler and operating system are you using?

  • Compiler: Apple clang version 12.0.5 (clang-1205.0.22.9)
  • Operating system: Darwin

Which version of the library did you use?

  • latest release version 3.10.2
  • other release - please state the version: 3.7.0
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
@nlohmann
Copy link
Owner

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Sep 22, 2021
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