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

Regression: call to member function 'value' is ambiguous #3652

Closed
2 tasks
sjoubert opened this issue Aug 2, 2022 · 2 comments · Fixed by #3663
Closed
2 tasks

Regression: call to member function 'value' is ambiguous #3652

sjoubert opened this issue Aug 2, 2022 · 2 comments · Fixed by #3663
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@sjoubert
Copy link

sjoubert commented Aug 2, 2022

Description

A call to value with a default int value and std::string is now ambiguous in the latest version.

To make it compile I need either to wrap the key value into a std::string_view type or explicitly specify the key template parameter to std::string. None of these spelling are compatible with the previous working version (3.10.5)

Reproduction steps

Minimal code example compiled using C++20 and version 3.11.1
The same code compiles correctly without warning using version 3.10.5

Expected vs. actual results

Results:

  • g++-12: warning about ambiguous call, but compilation proceeds
  • clang+-14: error about ambiguous call
    Expected: no compilation error on code previously working

Minimal code example

#include <nlohmann/json.hpp>

int main()
{
    nlohmann::json data;
    std::string key = "key";
    data.value(key, 0);
}

Error messages

<source>:7:10: error: call to member function 'value' is ambiguous
    data.value(key, 0);
    ~~~~~^~~~~
/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:21173:42: note: candidate function [with KeyType = std::basic_string<char>, ValueType = int, $2 = 0]
    typename std::decay<ValueType>::type value(const KeyType& key, ValueType && default_value) const
                                         ^
/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:21245:14: note: candidate function [with KeyType = std::basic_string<char> &, $1 = 0]
    string_t value(KeyType && key, const char* default_value) const
             ^
1 error generated.

Compiler and operating system

g++-12 (warning) and clang++-14 (error) with -std=c++20

Library version

3.11.1

Validation

@falbrechtskirchinger
Copy link
Contributor

Confirmed. A bit concerning that this wasn't caught by the unit tests. :-/
Fixing this is going to be a pain …

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Aug 7, 2022
@nlohmann nlohmann added this to the Release 3.11.2 milestone Aug 7, 2022
@dns13
Copy link
Contributor

dns13 commented Aug 8, 2022

This also applies for nullptr_t as the default value. But #3663 also fixed this - it's working in dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants