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

std::shared_ptr<T> == nlohmann::json compiles, which seem undesirable #3026

Closed
2 of 3 tasks
drussel opened this issue Sep 22, 2021 · 4 comments
Closed
2 of 3 tasks

std::shared_ptr<T> == nlohmann::json compiles, which seem undesirable #3026

drussel opened this issue Sep 22, 2021 · 4 comments

Comments

@drussel
Copy link

drussel commented Sep 22, 2021

Specifically std::shared_ptr<nlohmann::json>() == nlohmann::json() compiles (where one forgot to deference the shared_ptr before comparing).

What is the issue you have?

It is easy to miss dereferencing the pointer and so have the comparison not be as desired.

Please describe the steps to reproduce the issue.

std::shared_ptr<nlohmann::json>() == nlohmann::json()

Can you provide a small but working code example?

std::shared_ptr<nlohmann::json>() == nlohmann::json() (which is true) or std::make_shared<nlohmann::json>() == nlohmann::json() (which is false)

What is the expected behavior?

A compilation error would be really nice as it is very likely a bug.

And what is the actual behavior instead?

Compiles (as far as I know, the comparison result is what you would expect given that it compiles.

Which compiler and operating system are you using?

  • Compiler: apple-clang 12,13. Visual Studio 2017. Gcc 9.
  • Operating system: various

Which version of the library did you use?

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

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

@gregmarr
Copy link
Contributor

This is due to the implicit conversions/constructors in the library. If you disable them, then this code no longer compiles. See here for how to disable them:
https://github.com/nlohmann/json#implicit-conversions

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 9, 2022
@maddanio
Copy link

so this issue can be closed, right? works as designed?

@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 14, 2022
@drussel
Copy link
Author

drussel commented Jan 15, 2022

Works as designed and I can’t think of a better design.

@drussel drussel closed this as completed Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants