Closed
Description
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
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.