Commit Graph

109 Commits (c35d260c2fb91b8a53e585d480607a0f088cbbbb)

Author SHA1 Message Date
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
Niels Lohmann 9cca280a4d
JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
Niels Lohmann f56c6e2e30
Update documentation for the next release (#4216) 2023-11-26 15:51:19 +01:00
Niels Lohmann a0c1318830
Fix CI + new Doctest (#3985) 2023-05-21 17:23:18 +02:00
Raphael Grimm bbe337c3a3
Prevent memory leak when exception is thrown in adl_serializer::to_json (#3901)
Co-authored-by: barcode <barcode@example.com>
2023-03-08 13:43:45 +01:00
Niels Lohmann 9d69186291
🔖 set version to 3.11.2 2022-08-12 15:04:06 +02:00
Florian Albrechtskirchinger f1e34070d2
Fix 'const' qualifier on bool& has no effect (#3678)
* Fix 'const' qualifier on bool& has no effect

Thanks, @georgthegreat, for pointing out this issue.

* Extend std::vector<bool> unit test
2022-08-07 13:50:08 +02:00
Niels Lohmann f2020da0dd
🔖 set version to 3.11.1 2022-08-01 23:27:58 +02:00
Niels Lohmann ce0e13ccea
🔖 set version to 3.11.0 2022-07-31 23:19:06 +02:00
Florian Albrechtskirchinger d909f80960
Add versioned, ABI-tagged inline namespace and namespace macros (#3590)
* Add versioned inline namespace

Add a versioned inline namespace to prevent ABI issues when linking code
using multiple library versions.

* Add namespace macros

* Encode ABI information in inline namespace

Add _diag suffix to inline namespace if JSON_DIAGNOSTICS is enabled, and
_ldvcmp suffix if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON is enabled.

* Move ABI-affecting macros into abi_macros.hpp

* Move std_fs namespace definition into std_fs.hpp

* Remove std_fs namespace from unit test

* Format more files in tests directory

* Add unit tests

* Update documentation

* Fix GDB pretty printer

* fixup! Add namespace macros

* Derive ABI prefix from NLOHMANN_JSON_VERSION_*
2022-07-30 21:59:13 +02:00
Florian Albrechtskirchinger a87c1885cb
Re-add value_type detection to distinguish string types (#3604)
* Re-add value_type detection to is_constructible_string_type trait

* Add value_type detection to from_json for strings
2022-07-28 21:52:23 +02:00
Niels Lohmann 527da54dcb
Use REUSE framework (#3546)
* 📄 add licenses

* 👷 add REUSE compliance check

* 📝 add badge for REUSE

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-07-20 12:38:07 +02:00
Richard Hozák f6acdbec2c
Allow disabling default enum conversions (#3536) 2022-06-16 19:34:32 +02:00
Florian Albrechtskirchinger 9c31d54389
Add to_json() for std::vector<bool>::reference (#3534) 2022-06-13 13:21:55 +02:00
Florian Albrechtskirchinger 6b97599a27
Fix C++20/gcc-12 issues (Part 2) (#3446)
* Add C++20 3-way comparison operator and fix broken comparisons

Fixes #3207.
Fixes #3409.

* Fix iterators to meet (more) std::ranges requirements

Fixes #3130.
Related discussion: #3408

* Add note about CMake standard version selection to unit tests

Document how CMake chooses which C++ standard version to use when
building tests.

* Update documentation

* CI: add legacy discarded value comparison

* Fix internal linkage errors when building a module
2022-05-29 13:08:06 +02:00
Florian Albrechtskirchinger 616caea27a
Re-template json_pointer on string type (#3415)
* Make exception context optional

Change exception context parameter to pointer and replace context with
nullptr where appropriate.

* Support escaping other string types

* Add string concatenation function

Add variadic concat() function for concatenating char *, char, and
string types.

* Replace string concatenations using + with concat()

* Template json_pointer on string type

Change json_pointer from being templated on basic_json to being
templated on string type.

* Add unit test for #3388

Closes #3388.

* Fix regression test for #2958

* Add backwards compatibility with json_pointer<basic_json>

* Update json_pointer docs

* Allow comparing different json_pointers

* Update version numbers
2022-04-12 14:18:16 +02:00
Florian Albrechtskirchinger 261cc4e509
Fix constraints on from_json() for strings (#3427)
Constrain from_json() overload for StringType to not accept json_ref and
require it to be assignable, instead of constructible, from
basic_json::string_t.

Re-enable C++14 tests on Clang <4.0.

Fixes #3171.
Fixes #3267.
Fixes #3312.
Fixes #3384.
2022-04-08 10:22:47 +02:00
Florian Albrechtskirchinger c2054b96b9
Restore disabled check for #3070 (except on MSVC) (#3421)
Restore the previously disabled check for regression #3070 on all
compilers but MSVC.

To summarize the issue:
Given namespace fs = std::filesystem.
On MSVC attempting to construct an fs::path from json results in an
ambiguous overload resolution because fs::path can be constructed from
both a std::string as well as another fs::path.
To the best of my knowledge there is no way to fix an ambiguous overload
situation involving a type we do not control and with json implicitly
converting to both std::string and fs::path.

Re-enabling the check where it compiles and keeping it disabled for MSVC
is the best we can do.

Closes #3377 and #3382.
2022-04-06 08:25:35 +02:00
Florian Albrechtskirchinger ad103e5b45
Improve unit testing (Part 1) (#3380)
* Refactor unit test creation

Add functions for creating tests and to supply test- and
standard-specific build settings.

Raises minimum CMake version to 3.13 in test directory.

json_test_add_test_for(
    <file>
    MAIN <main>
    [CXX_STANDARDS <version_number>...] [FORCE])

Given a <file> unit-foo.cpp, produces

    test-foo_cpp<version_number>

if C++ standard <version_number> is supported by the compiler and
thesource file contains JSON_HAS_CPP_<version_number>.  Use FORCE to
create the test regardless of the file containing
JSON_HAS_CPP_<version_number>.  Test targets are linked against <main>.
CXX_STANDARDS defaults to "11".

json_test_set_test_options(
    all|<tests>
    [CXX_STANDARDS all|<args>...]
    [COMPILE_DEFINITIONS <args>...]
    [COMPILE_FEATURES <args>...]
    [COMPILE_OPTIONS <args>...]
    [LINK_LIBRARIES <args>...]
    [LINK_OPTIONS <args>...])

Supply test- and standard-specific build settings.
Specify multiple tests using a list e.g., "test-foo;test-bar".

Must be called BEFORE the test is created.

* Use CMAKE_MODULE_PATH

* Don't undef some macros if JSON_TEST_KEEP_MACROS is defined

* Use JSON_TEST_KEEP_MACROS

Incidentally enables the regression tests for #2546 and #3070.

A CHECK_THROWS_WITH_AS in #3070 was disabled which is tracked in #3377
and a line in from_json(..., std_fs::path&) was marked with LCOV_EXCL_LINE.

* Add three-way comparison feature test macro

* Disable broken comparison if JSON_HAS_THREE_WAY_COMPARISON

* Fix redefinition of inline constexpr statics

Redelcaration of inline constexpr static data members in namespace scope
was deprecated in C++17. Fixes -Werror=deprecated compilation failures.

* Fix more test build failures due to missing noexcept

* CI: update cmake_flags test to use CMake 3.13 in test directory

Also change default for JSON_BuildTests option to depend on CMake
version.

* CI: turn *_CXXFLAGS into CMake lists

* CI: use JSON_TestStandards to set CXX_STANDARD

* CI: pass extra CXXFLAGS to standards tests
2022-03-24 07:54:07 +01:00
Niels Lohmann 29cd970b94
Consolidate documentation (#3071)
* 🔥 consolidate documentation
* ♻️ overwork std specializations
* 🚚 move images files to mkdocs
* ♻️ fix URLs
* 🔧 tweak MkDocs configuration
* 🔧 add namespaces
* 📝 document deprecations
* 📝 document documentation generation
* 🚸 improve search
* 🚸 add examples
* 🚧 start adding documentation for macros
* 📝 add note for https://github.com/nlohmann/json/issues/874#issuecomment-1001699139
* 📝 overwork example handling
* 📝 fix Markdown tables
2021-12-29 13:41:01 +01:00
Niels Lohmann 6d3115924c
Add C++17 copies of the test binaries (#3101)
* ⚗️ add C++17 copies of the test binaries
* ⚗️ use proper header for filesystem
* 🚨 fix warnings
* ⚗️ do not use too old compilers with C++17
*  add test
* 🔨 add more constraints #3097
* ⚗️ use fix from https://github.com/nlohmann/json/pull/3101#issuecomment-998788786
* ⚗️ use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90050
* 👷 use published CI image
2021-12-29 09:47:05 +01:00
Théo DELRIEU 0e694b4060
fix std::filesystem::path regression (#3073)
* meta: rework is_compatible/is_constructible_string_type

These type traits performed an incorrect and insufficient check.

Converting to a std::filesystem::path used to work by accident thanks to
these brittle constraints, but the clean-up performed in #3020 broke them.

* support std::filesystem::path

Fixes #3070
2021-10-14 19:19:46 +02:00
Pierre Hallot 433604843d
Fix extra ";" clang warnings 2021-08-19 17:04:34 +02:00
Ferry Huberts 44d60f8d14 All: fix warnings when compiling with -Wswitch-enum
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
2021-08-12 16:33:50 +02:00
Niels Lohmann e20f3f95eb
🚨 guard GCC pragmas #2924 2021-08-11 23:55:46 +02:00
Sven Fink 353d59717e Add more suppressions on float comparisons 2021-08-04 08:34:53 +02:00
Niels Lohmann ecaac22656
💡 add comment to describe j.m_value.destroy(j.m_type) calls 2021-07-15 20:34:50 +02:00
Niels Lohmann f6863e062c
🐛 fix leak for all types 2021-07-15 20:32:37 +02:00
Niels Lohmann 0011cd1b72
🐛 fix leak for strings 2021-07-15 13:12:21 +02:00
Niels Lohmann c1298e69a6
🐛 fix leak for strings 2021-07-15 12:52:17 +02:00
Niels Lohmann 6cbdc83994
🐛 fix leak for strings 2021-07-15 12:47:15 +02:00
Anthony VH 2b865131d8 Fixing CI errors. 2021-03-24 23:33:21 +01:00
Anthony VH 333612ce35 Merge remote-tracking branch 'upstream/develop' into non_default_constructable_stl_containers 2021-03-24 12:33:57 +01:00
Niels Lohmann 6f551930e5
🚨 add new CI and fix warnings (#2561)
* ⚗️ move CI targets to CMake
* ♻️ add target for cpplint
* ♻️ add target for self-contained binaries
* ♻️ add targets for iwyu and infer
* 🔊 add version output
* ♻️ add target for oclint
* 🚨 fix warnings
* ♻️ rename targets
* ♻️ use iwyu properly
* 🚨 fix warnings
* ♻️ use iwyu properly
* ♻️ add target for benchmarks
* ♻️ add target for CMake flags
* 👷 use GitHub Actions
* ⚗️ try to install Clang 11
* ⚗️ try to install GCC 11
* ⚗️ try to install Clang 11
* ⚗️ try to install GCC 11
* ⚗️ add clang analyze target
* 🔥 remove Google Benchmark
* ⬆️ Google Benchmark 1.5.2
* 🔥 use fetchcontent
* 🐧 add target to download a Linux version of CMake
* 🔨 fix dependency
* 🚨 fix includes
* 🚨 fix comment
* 🔧 adjust flags for GCC 11.0.0 20210110 (experimental)
* 🐳 user Docker image to run CI
* 🔧 add target for Valgrind
* 👷 add target for Valgrind tests
* ⚗️ add Dart
*  remove Dart
* ⚗️ do not call ctest in test subdirectory
* ⚗️ download test data explicitly
* ⚗️ only execute Valgrind tests
* ⚗️ fix labels
* 🔥 remove unneeded jobs
* 🔨 cleanup
* 🐛 fix OCLint call
*  add targets for offline and git-independent tests
*  add targets for C++ language versions and reproducible tests
* 🔨 clean up
* 👷 add CI steps for cppcheck and cpplint
* 🚨 fix warnings from Clang-Tidy
* 👷 add CI steps for Clang-Tidy
* 🚨 fix warnings
* 🔧 select proper binary
* 🚨 fix warnings
* 🚨 suppress some unhelpful warnings
* 🚨 fix warnings
* 🎨 fix format
* 🚨 fix warnings
* 👷 add CI steps for Sanitizers
* 🚨 fix warnings
*  add optimization to sanitizer build
* 🚨 fix warnings
* 🚨 add missing header
* 🚨 fix warnings
* 👷 add CI step for coverage
* 👷 add CI steps for disabled exceptions and implicit conversions
* 🚨 fix warnings
* 👷 add CI steps for checking indentation
* 🐛 fix variable use
* 💚 fix build
*  remove CircleCI
* 👷 add CI step for diagnostics
* 🚨 fix warning
* 🔥 clean Travis
2021-03-24 07:15:18 +01:00
Niels Lohmann 4917e7c259
Merge branch 'develop' of https://github.com/nlohmann/json into diagnostics
 Conflicts:
	include/nlohmann/detail/input/parser.hpp
	single_include/nlohmann/json.hpp
2021-02-07 17:45:09 +01:00
Niels Lohmann ffdeb77468
🚨 fix warnings #2615 2021-01-27 12:54:46 +01:00
Niels Lohmann 74cc0ab470
♻️ remove diagnostics_t class 2021-01-25 13:47:50 +01:00
Niels Lohmann 0d1fb383b7
👌 address comment 2021-01-14 22:05:08 +01:00
Niels Lohmann b9d3aa4067
♻️ split set_parent function 2021-01-14 21:55:49 +01:00
Anthony VH d7c0f157c5 Merged from_json for pair and tuple to try to fix C2995 error in old MSVC versions. 2021-01-13 20:47:03 +01:00
Anthony VH 6278f31d23 Simplify from_json overloads. 2021-01-12 18:28:29 +01:00
Anthony VH 672e8bfc1d Fixed std::pair trying to deserialize via array functions. 2021-01-11 18:16:15 +01:00
Niels Lohmann ff57bdcc8b
🐛 fix invariants 2021-01-10 22:40:50 +01:00
Anthony VH 23f462b598 Reduced code duplication, renamed tag to identity_tag. 2021-01-10 19:23:32 +01:00
Niels Lohmann e160749003
♻️ move diagnostic code in header 2021-01-09 19:21:18 +01:00
Anthony VH c0a8b45bbb Renamed template parameter and added some comments. 2021-01-09 17:45:56 +01:00
Anthony VH 1e825e4f92 Add support for deserialization of STL containers of non-default constructable types (fixes #2574). 2021-01-09 00:08:27 +01:00
Niels Lohmann 7b047861b0
🚧 add diagnostics to exceptions 2021-01-02 13:44:41 +01:00
Théo DELRIEU 74b446f5fd
add a switch to enable implicit conversions (defaults to true)
wrap implicit conversions tests around the JSON_USE_IMPLICIT_CONVERSIONS
macro
2020-07-22 10:49:01 +02:00
Niels Lohmann 8d295235a5
🔥 remove unused boolean_operators.hpp header 2020-07-11 19:20:44 +02:00