-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected conversion from 'true'/'false' to some integer types #4358
Comments
I am having the same issue and apologies if I am not understanding this correctly as I am new to C++ and have only just started using this library, but it looks like the integer value is not being considered a basic_json and so is calling the explicit cast from_json. At least the comment above the function leads me to believe this. |
hi i am working on this.Will get something by this weekend. |
Are you still working on this? I'm planning to look into it. |
If I'm planning on contributing, is there any guidelines or styles that I need to follow while writing the code? If yes, where can I read about it? Thanks. |
@amirghaz Do you need further assistance? |
@nlohmann I'm a beginner with this library, so any insight that you have is highly appreciated. |
The current proposal of #4523 is a breaking change. We need to decide how to guard this change to not affect client code. Yet another preprocessor macro? 🤔 |
I see, but I lack the experience dealing with preprocessor macro. @jboelterintc do you have any suggestion? |
I managed to write a (partial) fix that passed all 98 unit tests without using preprocessor macro. However, it is only a partial fix because, although all other integer types return a type error, uint8_t still perform the conversion. |
It seems my newest fix still fail some checks. Before moving forward with another fix, maybe we should discuss if the partial fix I mentioned above is the way to go. Currently, only int64_t and uint64_t will return a type error, and based on the unit tests, it seems that conversion from uin8_t to boolean is required (except if there is a way to circumvent this that I am unaware of). So, any fix potentially will still have some inconsistencies because of uint8_t. Is this really what we want? Any opinion @nlohmann @jboelterintc on this? |
Description
Converting from
"value": true
or"value": false
behaves unexpectedly and differently for certain integer types.I was expecting all conversions from a boolean true/false to integer value to fail, however it is stored as a 1 or 0.
Reproduction steps
Given:
This will result in a
1
invalue
.Using
uint64_t
will throw atype_error
.Expected vs. actual results
I expected all boolean to integer conversions to fail. Instead a
true
->1
andfalse
->0
for certain integer values.Various integer conversions - https://godbolt.org/z/7Wrh6EanW
The
uint64_t
case is taking the path throughget_arithmetic_value
The
int
case is taking the path throughMinimal code example
https://godbolt.org/z/fs4frqz7G
Error messages
No response
Compiler and operating system
Latest MSVC & Clang
Library version
3.11.3
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: