open-source-parsers / open-source-parsers/jsoncpp
ambiguous overload for 'operator[]' of Json::Value' when compiled for x64
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.7k
- Avg merge
- 31m
- Merged PRs (30d)
- 1
Description
Describe the bug
When switching from x86 to x64 I run into following compiler error:
error: ambiguous overload for 'operator[]' (operand types are 'const Json::Value' and 'size_t' {aka 'long long unsigned int'})
const Json::Value& jsLoop = jsLoopList[loop];
^
In file included from Model.cc:3:
..\include/json/json.h:977:16: note: candidate: 'const Json::Value& Json::Value::operator[](Json::Value::ArrayIndex) const'
const Value& operator[](ArrayIndex index) const;
^~~~~~~~
..\include/json/json.h:978:16: note: candidate: 'const Json::Value& Json::Value::operator[](int) const'
const Value& operator[](int index) const;
It is triggered for example by following code snippet:
Json::Value jsLoopList;
// initialize jsLoopList as array
for(size_t loop = 0; loop < loopCount; ++loop) {
const Json::Value& jsLoop = jsLoopList[loop]; // works for x86, fails for x64
// do some stuff ...
}
The problem is that with the change from 32 to 64 bit the type of size_t changed and now the compiler does not find an exact match.
The solution is to switch to int, but this have the drawback that negative values are possible. The alternative is to use Json::ArrayIndex.
Still it would be great if the array operator of Json::Value can be used like for container classes from the standard lib, e.g. for std::vector.
To Reproduce
Steps to reproduce the behavior:
- Compile code snippet for x64
Expected behavior
Same behaviour as for x86: The code compiles and works.
Desktop:
- OS: Windows
- MinGW: g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
- Tested with jsoncpp 0.9.5 and 0.10.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in include/json/json.h at the const Json::Value::operator[] overloads shown in the compiler output. Reproduce the provided loop with a 64-bit MinGW build, then inspect the surrounding public API and existing behavior for int and Json::ArrayIndex. Done means the reported x64 size_t use case has an unambiguous, compatible outcome without allowing unintended negative array indexes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100