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

Braced initialization and aggregate initialization behavior is different for json::array() function call. #2848

Closed
1 of 3 tasks
Elnee opened this issue Jul 2, 2021 · 4 comments
Labels
kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@Elnee
Copy link

Elnee commented Jul 2, 2021

What is the issue you have?

Braced initialization of variable with json::array() has different result from aggregate initialization.

Please describe the steps to reproduce the issue.

  1. Run the code below.

Can you provide a small but working code example?

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

int main(int argc, char* argv[])
{
  auto aggregate = nlohmann::json::array();
  std::cout << aggregate.size() << std::endl;

  auto uniform{ nlohmann::json::array() };
  std::cout << uniform.size() << std::endl;
  
  return 0;
}

What is the expected behavior?

0 size for both.

And what is the actual behavior instead?

0 size for aggregate initialization and 1 size for braced initialization.

Which compiler and operating system are you using?

  • Compiler: gcc 9.3.0
  • Operating system: Ubuntu 20.04

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch
@Elnee Elnee added the kind: bug label Jul 2, 2021
@gregmarr
Copy link
Contributor

gregmarr commented Jul 2, 2021

See #2311

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Jul 2, 2021
@nlohmann nlohmann closed this as completed Jul 2, 2021
@Elnee
Copy link
Author

Elnee commented Jul 3, 2021

I am sorry, but I don't understand how those issues related to this issue. They all talk about different behavior for different compilers, but this issue talks about different behavior on the same gcc compiler between braced and aggregate initializations.

@nlohmann
Copy link
Owner

nlohmann commented Jul 3, 2021

This is the same issue as #2311. In Clang, both initializations result in the same value, whereas GCC interprets braced initialization as putting the value into a new array.

@Elnee
Copy link
Author

Elnee commented Jul 3, 2021

Ok. Thank you for explanation.

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

3 participants