json/tests/src
Juan Carlos Arevalo Baeza a259ecc51e
Fix to_json for enums when the enum has an unsigned underlying type. (#4237)
* Enhance the UDT unit test to expose the issue

Add a new enum type with uint64_t as the underlying type.
Use it in the overall UDT. Not strictly needed, but it helps exercise its expected usage.
Create an object of this enum type with a large value (negative if cast to int64_t).
Perform several checks on this object as converted to `json`, which fail without the fix.

* Fix the issue in the relevant `to_json` overload.

Select the correct json type depending on the signedness of the enum's underlying type.
This fixes the new checks in the unit test.

* Add the fix to the single_include

I ran `make pretty` but that modified 20 files, performing a significant amount of indentation changes, none of them related to my change.
I ran `make amalgamate`, but that did nothing. Apparently, the make rule won't run if the single_include files have already been updated by `make pretty`.
I forced `make amalgamate` to do the work by touching the file with the fix.
I then decided to keep just the minimal needed change: the addition of the fix to the single_include file.

I just am not conversant enough in Linux to know whether I installed astyle correctly (had to clone the source from a beta branch and build, in order to get support for `--squeeze-lines`).

* Resolve CI errors and use qualified `std::uint64_t`

The fix was relying on implicit conversions in the non-taken branch.
- Ordinarily (work on a C++20 codebase) I would have used `if constexpr` here, sidestepping the issue, but that's not available on C++11 so I didn't bother.
- So instead of an `if` statement, I used a compile-time constant to select the correct overload.
- This is arguably better in this case, anyway.

I was using function-style casts for typed constants, which I consider superior for constants, but the CI checks disagree, so changed all to `static_cast`.
- For some reason, the CI checks didn't point at all of them, so I hope I caught them all myself.

Built with clang14 and all unit tests pass.

---------

Co-authored-by: Juan Carlos Arevalo Baeza (JCAB) <jcab@ntdev.microsoft.com>
2023-12-14 09:26:10 +01:00
..
fuzzer-driver_afl.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_bjdata.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_bson.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_cbor.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_json.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_msgpack.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
fuzzer-parse_ubjson.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
make_test_data_available.hpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
test_utils.hpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-32bit.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-algorithms.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-allocator.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-alt-string.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-assert_macro.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-binary_formats.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-bjdata.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-bson.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-byte_container_with_subtype.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-capacity.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-cbor.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-class_const_iterator.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-class_iterator.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-class_lexer.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-class_parser.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-comparison.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-concepts.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-constructor1.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-constructor2.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-convenience.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-conversions.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-custom-base-class.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-deserialization.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-diagnostics.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-disabled_exceptions.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-element_access1.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-element_access2.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-hash.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-inspection.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-items.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-iterators1.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-iterators2.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-json_patch.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-json_pointer.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-large_json.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-merge_patch.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-meta.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-modifiers.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-msgpack.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-no-mem-leak-on-adl-serialize.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-noexcept.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-ordered_json.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-ordered_map.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-pointer_access.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-readme.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-reference_access.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-regression1.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-regression2.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-serialization.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-testsuites.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-to_chars.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-type_traits.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-ubjson.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-udl.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-udt_macro.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-udt.cpp Fix to_json for enums when the enum has an unsigned underlying type. (#4237) 2023-12-14 09:26:10 +01:00
unit-unicode1.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-unicode2.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-unicode3.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-unicode4.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-unicode5.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-user_defined_input.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-windows_h.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit-wstring.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
unit.cpp JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00