diff --git a/.clang-tidy b/.clang-tidy index a28335936d..33cf84821f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,7 @@ Checks: '*, + -altera-struct-pack-align, -android-cloexec-fopen, + -concurrency-mt-unsafe, -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, @@ -30,6 +32,7 @@ Checks: '*, -misc-non-private-member-variables-in-classes, -modernize-use-trailing-return-type, -readability-function-size, + -readability-function-cognitive-complexity, -readability-magic-numbers, -readability-redundant-access-specifiers, -readability-uppercase-literal-suffix' diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 0ed01fd4ec..3e650f77ca 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -47,7 +47,7 @@ assignees: '' -- [ ] latest release version 3.10.2 +- [ ] latest release version 3.10.3 - [ ] other release - please state the version: ___ - [ ] the `develop` branch diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0b296047e9..ea9edc9770 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -11,20 +11,9 @@ on: jobs: ci_test_clang: runs-on: ubuntu-latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 steps: - uses: actions/checkout@v2 - - name: install_ninja - run: | - sudo apt update - sudo apt install ninja-build - shell: bash - - name: install_clang - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 11 - sudo apt-get install clang-tools-11 - shell: bash - name: cmake run: cmake -S . -B build -DJSON_CI=On - name: build @@ -32,7 +21,7 @@ jobs: ci_test_gcc: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 steps: - uses: actions/checkout@v2 - name: cmake @@ -42,7 +31,7 @@ jobs: ci_static_analysis: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 strategy: matrix: target: [ci_clang_tidy, ci_cppcheck, ci_test_valgrind, ci_test_clang_sanitizer, ci_test_amalgamation, ci_clang_analyze, ci_cpplint, ci_cmake_flags, ci_single_binaries, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_infer] @@ -55,7 +44,7 @@ jobs: ci_cmake_options: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 strategy: matrix: target: [ci_test_diagnostics, ci_test_noexceptions, ci_test_noimplicitconversions] @@ -68,7 +57,7 @@ jobs: ci_test_coverage: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 steps: - uses: actions/checkout@v2 - name: cmake @@ -88,10 +77,10 @@ jobs: ci_test_compilers: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 strategy: matrix: - compiler: [g++-4.8, g++-4.9, g++-5, g++-7, g++-8, g++-9, g++-10, clang++-3.5, clang++-3.6, clang++-3.7, clang++-3.8, clang++-3.9, clang++-4.0, clang++-5.0, clang++-6.0, clang++-7, clang++-8, clang++-9, clang++-10, clang++-11] + compiler: [g++-4.8, g++-4.9, g++-5, g++-7, g++-8, g++-9, g++-10, clang++-3.5, clang++-3.6, clang++-3.7, clang++-3.8, clang++-3.9, clang++-4.0, clang++-5.0, clang++-6.0, clang++-7, clang++-8, clang++-9, clang++-10, clang++-11, clang++-12] steps: - uses: actions/checkout@v2 - name: cmake @@ -101,7 +90,7 @@ jobs: ci_test_standards: runs-on: ubuntu-latest - container: nlohmann/json-ci:latest + container: ghcr.io/nlohmann/json-ci:v1.0.0 strategy: matrix: standard: [11, 14, 17, 20] diff --git a/.gitignore b/.gitignore index bf938c8ea8..a465207896 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,6 @@ build build_coverage clang_analyze_build -doc/xml -doc/html -me.nlohmann.json.docset - benchmarks/files/numbers/*.json .wsjcpp-logs/* @@ -27,10 +23,11 @@ benchmarks/files/numbers/*.json test/test-* /.vs +doc/html doc/mkdocs/venv/ doc/mkdocs/docs/images doc/mkdocs/docs/examples doc/mkdocs/site doc/mkdocs/docs/__pycache__/ -doc/xml -/doc/docset/nlohmann_json.docset/ +/doc/docset/JSON_for_Modern_C++.docset/ +/doc/docset/JSON_for_Modern_C++.tgz diff --git a/CITATION.cff b/CITATION.cff index 5dd4176977..86f1682f7e 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -7,7 +7,7 @@ authors: email: mail@nlohmann.me website: https://nlohmann.me title: "JSON for Modern C++" -version: 3.10.2 +version: 3.10.3 date-released: 2021 license: MIT repository-code: "https://github.com/nlohmann" diff --git a/CMakeLists.txt b/CMakeLists.txt index 38d7040105..fcc66fc4ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.1) ## PROJECT ## name and version ## -project(nlohmann_json VERSION 3.10.2 LANGUAGES CXX) +project(nlohmann_json VERSION 3.10.3 LANGUAGES CXX) ## ## MAIN_PROJECT CHECK diff --git a/ChangeLog.md b/ChangeLog.md index 4ef9b9beb2..88964ab354 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,16 +1,47 @@ # Changelog All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [3.10.2](https://github.com/nlohmann/json/releases/tag/3.10.2) (2021-08-26) +## [3.10.3](https://github.com/nlohmann/json/releases/tag/3.10.3) (2021-10-08) + +[Full Changelog](https://github.com/nlohmann/json/compare/v3.10.2...3.10.3) + +- Parsing an emtpy string returns a string with size 1 instead of expected 0 [\#3057](https://github.com/nlohmann/json/issues/3057) +- Linking error "duplicate symbol: std::type\_info::operator==" on static build with MinGW [\#3042](https://github.com/nlohmann/json/issues/3042) +- Yet another assertion failure when inserting into arrays with JSON\_DIAGNOSTICS set [\#3032](https://github.com/nlohmann/json/issues/3032) +- accept and parse function not work well with a pure number string [\#3029](https://github.com/nlohmann/json/issues/3029) +- push\_back doesn't work for serializing containers [\#3027](https://github.com/nlohmann/json/issues/3027) +- Strange behaviour when creating array with single element [\#3025](https://github.com/nlohmann/json/issues/3025) +- Input ordered\_json doesn't work [\#3023](https://github.com/nlohmann/json/issues/3023) +- Issue iterating through 'items' [\#3021](https://github.com/nlohmann/json/issues/3021) +- Cannot spell the namespace right [\#3015](https://github.com/nlohmann/json/issues/3015) +- JSON Parse error when reading json object from file [\#3011](https://github.com/nlohmann/json/issues/3011) +- Parent pointer not properly set when using update\(\) [\#3007](https://github.com/nlohmann/json/issues/3007) +- Overwriting terminated null character [\#3001](https://github.com/nlohmann/json/issues/3001) +- 'operator =' is ambiguous on VS2017 [\#2997](https://github.com/nlohmann/json/issues/2997) +- JSON Patch for Array Elements [\#2994](https://github.com/nlohmann/json/issues/2994) +- JSON Parse throwing error [\#2983](https://github.com/nlohmann/json/issues/2983) +- to\_{binary format} does not provide a mechanism for specifying a custom allocator for the returned type. [\#2982](https://github.com/nlohmann/json/issues/2982) +- 3.10.1 zip json.hpp has version number 3.10.0 instead of 3.10.1 [\#2973](https://github.com/nlohmann/json/issues/2973) +- Assertion failure when serializing array with JSON\_DIAGNOSTICS set [\#2926](https://github.com/nlohmann/json/issues/2926) + +- Fix Clang version [\#3040](https://github.com/nlohmann/json/pull/3040) ([nlohmann](https://github.com/nlohmann)) +- Fix assertion failure for JSON\_DIAGNOSTICS [\#3037](https://github.com/nlohmann/json/pull/3037) ([carlsmedstad](https://github.com/carlsmedstad)) +- meta: fix is\_compatible/constructible traits [\#3020](https://github.com/nlohmann/json/pull/3020) ([theodelrieu](https://github.com/theodelrieu)) +- Set parent pointers for values inserted via update\(\) \(fixes \#3007\). [\#3008](https://github.com/nlohmann/json/pull/3008) ([AnthonyVH](https://github.com/AnthonyVH)) +- Allow allocators for output\_vector\_adapter [\#2989](https://github.com/nlohmann/json/pull/2989) ([nlohmann](https://github.com/nlohmann)) +- Re-add Clang 12 [\#2986](https://github.com/nlohmann/json/pull/2986) ([nlohmann](https://github.com/nlohmann)) +- Use new Docker image [\#2981](https://github.com/nlohmann/json/pull/2981) ([nlohmann](https://github.com/nlohmann)) +- Fix -Wunused warnings on JSON\_DIAGNOSTICS [\#2976](https://github.com/nlohmann/json/pull/2976) ([gcerretani](https://github.com/gcerretani)) +- Update docset generation script [\#2967](https://github.com/nlohmann/json/pull/2967) ([nlohmann](https://github.com/nlohmann)) + +## [v3.10.2](https://github.com/nlohmann/json/releases/tag/v3.10.2) (2021-08-26) -[Full Changelog](https://github.com/nlohmann/json/compare/v3.10.1...3.10.2) +[Full Changelog](https://github.com/nlohmann/json/compare/v3.10.1...v3.10.2) - Annoying -Wundef on new JSON\_DIAGNOSTICS macro [\#2975](https://github.com/nlohmann/json/issues/2975) - += issue with multiple redirection. [\#2970](https://github.com/nlohmann/json/issues/2970) - "incomplete type โ€˜nlohmann::detail::wide\_string\_input\_helper" compilation error [\#2969](https://github.com/nlohmann/json/issues/2969) -- Fix -Wunused warnings on JSON\_DIAGNOSTICS [\#2976](https://github.com/nlohmann/json/pull/2976) ([gcerretani](https://github.com/gcerretani)) - ## [v3.10.1](https://github.com/nlohmann/json/releases/tag/v3.10.1) (2021-08-24) [Full Changelog](https://github.com/nlohmann/json/compare/v3.10.0...v3.10.1) diff --git a/README.md b/README.md index 0276bc4372..803d953893 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e0d1a9d5d6fd46fcb655c4cb930bb3e8)](https://www.codacy.com/gh/nlohmann/json/dashboard?utm_source=github.com&utm_medium=referral&utm_content=nlohmann/json&utm_campaign=Badge_Grade) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/nlohmann/json.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/nlohmann/json/context:cpp) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/json.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json) -[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/7p8sQckddTc0Y81T) +[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/0LzTlmYG06u8qJN5) [![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](https://nlohmann.github.io/json/doxygen/index.html) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT) [![GitHub Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) @@ -90,6 +90,7 @@ Thanks everyone! :bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as many information as possible to help us understand and reproduce your issue. +There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as offline resource. ## Examples @@ -1038,7 +1039,7 @@ auto cbor = json::to_msgpack(j); // 0xD5 (fixext2), 0x10, 0xCA, 0xFE Though it's 2021 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work: - GCC 4.8 - 11.0 (and possibly later) -- Clang 3.4 - 12.0 (and possibly later) +- Clang 3.4 - 13.0 (and possibly later) - Apple Clang 9.1 - 12.4 (and possibly later) - Intel C++ Compiler 17.0.2 (and possibly later) - Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later) @@ -1110,7 +1111,8 @@ The following compilers are currently used in continuous integration at [Travis] | Clang 11.0.0 with GNU-like command-line | Windows-10.0.17763 | GitHub Actions | | Clang 11.0.0 with MSVC-like command-line | Windows-10.0.17763 | GitHub Actions | | Clang 11.0.0 (11.0.0-2~ubuntu20.04.1) | Ubuntu 20.04.2 LTS | GitHub Actions | -| Clang 12.1.0 (12.0.1-++20210423082613+072c90a863aa-1~exp1~20210423063319.76 | Ubuntu 20.04.2 LTS | GitHub Actions | +| Clang 12.0.0 (12.0.0-3ubuntu1~20.04.3) | Ubuntu 20.04.2 LTS | GitHub Actions | +| Clang 13.0.0 (13.0.0-++20210828094952+9c49fee5e7ac-1exp120210828075752.71 | Ubuntu 20.04.2 LTS | GitHub Actions | | Visual Studio 14 2015 MSVC 19.0.24241.7 (Build Engine version 14.0.25420.1) | Windows-6.3.9600 | AppVeyor | | Visual Studio 15 2017 MSVC 19.16.27035.0 (Build Engine version 15.9.21+g9802d43bc3 for .NET Framework) | Windows-10.0.14393 | AppVeyor | | Visual Studio 15 2017 MSVC 19.16.27045.0 (Build Engine version 15.9.21+g9802d43bc3 for .NET Framework) | Windows-10.0.14393 | GitHub Actions | @@ -1262,7 +1264,9 @@ If you are using [NuGet](https://www.nuget.org), you can use the package [nlohma If you are using [conda](https://conda.io/), you can use the package [nlohmann_json](https://github.com/conda-forge/nlohmann_json-feedstock) from [conda-forge](https://conda-forge.org) executing `conda install -c conda-forge nlohmann_json`. Please file issues [here](https://github.com/conda-forge/nlohmann_json-feedstock/issues). -If you are using [MSYS2](https://www.msys2.org/), your can use the [mingw-w64-nlohmann-json](https://packages.msys2.org/base/mingw-w64-nlohmann-json) package, just type `pacman -S mingw-w64-i686-nlohmann-json` or `pacman -S mingw-w64-x86_64-nlohmann-json` for installation. Please file issues [here](https://github.com/msys2/MINGW-packages/issues/new?title=%5Bnlohmann-json%5D) if you experience problems with the packages. +If you are using [MSYS2](https://www.msys2.org/), you can use the [mingw-w64-nlohmann-json](https://packages.msys2.org/base/mingw-w64-nlohmann-json) package, just type `pacman -S mingw-w64-i686-nlohmann-json` or `pacman -S mingw-w64-x86_64-nlohmann-json` for installation. Please file issues [here](https://github.com/msys2/MINGW-packages/issues/new?title=%5Bnlohmann-json%5D) if you experience problems with the packages. + +If you are using [MacPorts](https://ports.macports.org), execute `sudo port install nlohmann-json` to install the [nlohmann-json](https://ports.macports.org/port/nlohmann-json/) package. If you are using [`build2`](https://build2.org), you can use the [`nlohmann-json`](https://cppget.org/nlohmann-json) package from the public repository https://cppget.org or directly from the [package's sources repository](https://github.com/build2-packaging/nlohmann-json). In your project's `manifest` file, just add `depends: nlohmann-json` (probably with some [version constraints](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml#guide-add-remove-deps)). If you are not familiar with using dependencies in `build2`, [please read this introduction](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml). Please file issues [here](https://github.com/build2-packaging/nlohmann-json) if you experience problems with the packages. @@ -1591,6 +1595,8 @@ I deeply appreciate the help of the following people. - [Amir Masoud Abdol](https://github.com/amirmasoudabdol) updated the Homebrew command as nlohmann/json is now in homebrew-core. - [Hallot](https://github.com/Hallot) fixed some `-Wextra-semi-stmt warnings`. - [Giovanni Cerretani](https://github.com/gcerretani) fixed `-Wunused` warnings on `JSON_DIAGNOSTICS`. +- [Bogdan Popescu](https://github.com/Kapeli) hosts the [docset](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for offline documentation viewers. +- [Carl Smedstad](https://github.com/carlsmedstad) fixed an assertion error when using `JSON_DIAGNOSTICS`. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. @@ -1622,7 +1628,7 @@ The library itself consists of a single header file licensed under the MIT licen - [**send_to_wandbox**](https://github.com/nlohmann/json/blob/develop/doc/scripts/send_to_wandbox.py) to send code examples to [Wandbox](https://wandbox.org) - [**Travis**](https://travis-ci.org) for [continuous integration](https://travis-ci.org/nlohmann/json) on Linux and macOS - [**Valgrind**](https://valgrind.org) to check for correct memory management -- [**Wandbox**](https://wandbox.org) for [online examples](https://wandbox.org/permlink/7p8sQckddTc0Y81T) +- [**Wandbox**](https://wandbox.org) for [online examples](https://wandbox.org/permlink/0LzTlmYG06u8qJN5) ## Projects using JSON for Modern C++ diff --git a/cmake/ci.cmake b/cmake/ci.cmake index 3ae527b355..f748c760cc 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -13,7 +13,7 @@ execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VER string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}") message(STATUS "๐Ÿ”– Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})") -find_program(CLANG_TOOL NAMES clang++-HEAD clang++-12 clang++-11 clang++) +find_program(CLANG_TOOL NAMES clang++-HEAD clang++-13 clang++-12 clang++-11 clang++) execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION) string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}") message(STATUS "๐Ÿ”– Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})") @@ -79,7 +79,7 @@ message(STATUS "๐Ÿ”– Valgrind ${VALGRIND_TOOL_VERSION} (${VALGRIND_TOOL})") find_program(GENHTML_TOOL NAMES genhtml) find_program(PLOG_CONVERTER_TOOL NAMES plog-converter) find_program(PVS_STUDIO_ANALYZER_TOOL NAMES pvs-studio-analyzer) -find_program(SCAN_BUILD_TOOL NAMES scan-build-11 scan-build) +find_program(SCAN_BUILD_TOOL NAMES scan-build-12 scan-build-11 scan-build) # the individual source files file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp) @@ -96,6 +96,7 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp) # -Wno-padded We do not care about padding warnings. # -Wno-covered-switch-default All switches list all cases and a default case. # -Wno-weak-vtables The library is header-only. +# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536. set(CLANG_CXXFLAGS "-std=c++11 \ -Werror \ @@ -107,6 +108,7 @@ set(CLANG_CXXFLAGS "-std=c++11 \ -Wno-padded \ -Wno-covered-switch-default \ -Wno-weak-vtables \ + -Wno-reserved-identifier \ ") # Ignored GCC warnings: @@ -809,7 +811,7 @@ add_custom_target(ci_cmake_flags # Use more installed compilers. ############################################################################### -foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-7 g++-8 g++-9 g++-10 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11) +foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-7 g++-8 g++-9 g++-10 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11 clang++-12) find_program(COMPILER_TOOL NAMES ${COMPILER}) if (COMPILER_TOOL) add_custom_target(ci_test_compiler_${COMPILER} diff --git a/doc/Doxyfile b/doc/Doxyfile index 6217d1b10f..8ed6a667a1 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -5,7 +5,7 @@ #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "JSON for Modern C++" -PROJECT_NUMBER = 3.10.2 +PROJECT_NUMBER = 3.10.3 PROJECT_BRIEF = PROJECT_LOGO = OUTPUT_DIRECTORY = . @@ -252,7 +252,7 @@ MAN_LINKS = NO #--------------------------------------------------------------------------- # Configuration options related to the XML output #--------------------------------------------------------------------------- -GENERATE_XML = YES +GENERATE_XML = NO XML_OUTPUT = xml XML_PROGRAMLISTING = YES XML_NS_MEMB_FILE_SCOPE = NO diff --git a/doc/Makefile b/doc/Makefile index 9addd3401f..761dd4368d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -43,7 +43,7 @@ check_output: $(EXAMPLES:.cpp=.test) clean: - rm -fr me.nlohmann.json.docset html xml $(EXAMPLES:.cpp=) + rm -fr me.nlohmann.json.docset html $(EXAMPLES:.cpp=) $(MAKE) clean -C docset $(MAKE) clean -C mkdocs @@ -70,23 +70,3 @@ upload: clean doxygen check_output scripts/git-update-ghpages nlohmann/json html rm -fr html open http://nlohmann.github.io/json/ - - -########################################################################## -# docset -########################################################################## - -# create docset for Dash -docset: create_output - cp Doxyfile Doxyfile_docset - $(SED) -i 's/DISABLE_INDEX = NO/DISABLE_INDEX = YES/' Doxyfile_docset - $(SED) -i 's/SEARCHENGINE = YES/SEARCHENGINE = NO/' Doxyfile_docset - $(SED) -i 's@HTML_EXTRA_STYLESHEET = css/mylayout.css@HTML_EXTRA_STYLESHEET = css/mylayout_docset.css@' Doxyfile_docset - rm -fr html *.docset - doxygen Doxyfile_docset - $(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html - $(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html - make -C html - mv html/*.docset . - $(SED) -i 's@doxygen@json@' me.nlohmann.json.docset/Contents/Info.plist - rm -fr Doxyfile_docset html diff --git a/doc/docset/Makefile b/doc/docset/Makefile index 262540a0c2..e538661ecf 100644 --- a/doc/docset/Makefile +++ b/doc/docset/Makefile @@ -1,21 +1,25 @@ -nlohmann_json.docset: Info.plist docSet.sql +JSON_for_Modern_C++.docset: Info.plist docSet.sql $(MAKE) clean - mkdir -p nlohmann_json.docset/Contents/Resources/Documents/ - cp info.plist nlohmann_json.docset/Contents + mkdir -p JSON_for_Modern_C++.docset/Contents/Resources/Documents/ + cp icon*.png JSON_for_Modern_C++.docset + cp Info.plist JSON_for_Modern_C++.docset/Contents # build and copy documentation $(MAKE) build -C ../mkdocs - cp -r ../mkdocs/site/* nlohmann_json.docset/Contents/Resources/Documents + cp -r ../mkdocs/site/* JSON_for_Modern_C++.docset/Contents/Resources/Documents # patch CSS to hide navigation items - echo "\n\nheader, footer, navi, div.md-sidebar--primary, nav.md-tabs--active, a.md-content__button { display: none; }" >> nlohmann_json.docset/Contents/Resources/Documents/assets/stylesheets/main.b5d04df8.min.css + echo "\n\nheader, footer, navi, div.md-sidebar--primary, nav.md-tabs--active, a.md-content__button { display: none; }" >> "$$(ls JSON_for_Modern_C++.docset/Contents/Resources/Documents/assets/stylesheets/main.*.min.css)" # fix spacing - echo "\n\ndiv.md-sidebar div.md-sidebar--secondary, div.md-main__inner { top: 0; margin-top: 0 }" >> nlohmann_json.docset/Contents/Resources/Documents/assets/stylesheets/main.b5d04df8.min.css + echo "\n\ndiv.md-sidebar div.md-sidebar--secondary, div.md-main__inner { top: 0; margin-top: 0 }" >> "$$(ls JSON_for_Modern_C++.docset/Contents/Resources/Documents/assets/stylesheets/main.*.min.css)" # remove "JSON for Modern C++" from page titles - find nlohmann_json.docset/Contents/Resources/Documents -type f -exec gsed -i 's| - JSON for Modern C++||' {} + + find JSON_for_Modern_C++.docset/Contents/Resources/Documents -type f -exec gsed -i 's| - JSON for Modern C++||' {} + # clean up - rm nlohmann_json.docset/Contents/Resources/Documents/hooks.py - rm nlohmann_json.docset/Contents/Resources/Documents/sitemap.* + rm JSON_for_Modern_C++.docset/Contents/Resources/Documents/hooks.py + rm JSON_for_Modern_C++.docset/Contents/Resources/Documents/sitemap.* # generate index - sqlite3 nlohmann_json.docset/Contents/Resources/docSet.dsidx < docSet.sql + sqlite3 JSON_for_Modern_C++.docset/Contents/Resources/docSet.dsidx < docSet.sql + +JSON_for_Modern_C++.tgz: JSON_for_Modern_C++.docset + tar --exclude='.DS_Store' -cvzf JSON_for_Modern_C++.tgz JSON_for_Modern_C++.docset clean: - rm -fr nlohmann_json.docset + rm -fr JSON_for_Modern_C++.docset JSON_for_Modern_C++.tgz diff --git a/doc/docset/README.md b/doc/docset/README.md index b0dd7f81e7..79a778eb8f 100644 --- a/doc/docset/README.md +++ b/doc/docset/README.md @@ -11,3 +11,9 @@ make nlohmann_json.docset ``` The generated folder `nlohmann_json.docset` can then be opened in the documentation browser. + +A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B). + +## Licenses + +The [JSON logo](https://commons.wikimedia.org/wiki/File:JSON_vector_logo.svg) is public domain. diff --git a/doc/docset/docset.json b/doc/docset/docset.json new file mode 100644 index 0000000000..f8d4783023 --- /dev/null +++ b/doc/docset/docset.json @@ -0,0 +1,10 @@ +{ + "name": "JSON for Modern C++", + "version": "3.10.0", + "archive": "JSON_for_Modern_C++.tgz", + "author": { + "name": "Niels Lohmann", + "link": "https://twitter.com/nlohmann" + }, + "aliases": ["nlohmann/json"] +} diff --git a/doc/docset/icon.png b/doc/docset/icon.png new file mode 100644 index 0000000000..7197d0a754 Binary files /dev/null and b/doc/docset/icon.png differ diff --git a/doc/docset/icon@2x.png b/doc/docset/icon@2x.png new file mode 100644 index 0000000000..5f2fac87aa Binary files /dev/null and b/doc/docset/icon@2x.png differ diff --git a/doc/examples/README.link b/doc/examples/README.link index 48e6cce3a0..5b5ffab816 100644 --- a/doc/examples/README.link +++ b/doc/examples/README.link @@ -1 +1 @@ -online \ No newline at end of file +online \ No newline at end of file diff --git a/doc/examples/meta.output b/doc/examples/meta.output index 83c0917341..d28c1c88d6 100644 --- a/doc/examples/meta.output +++ b/doc/examples/meta.output @@ -2,7 +2,7 @@ "compiler": { "c++": "201103", "family": "clang", - "version": "12.0.5 (clang-1205.0.22.11)" + "version": "13.0.0 (clang-1300.0.29.3)" }, "copyright": "(C) 2013-2021 Niels Lohmann", "name": "JSON for Modern C++", @@ -11,7 +11,7 @@ "version": { "major": 3, "minor": 10, - "patch": 2, - "string": "3.10.2" + "patch": 3, + "string": "3.10.3" } } diff --git a/doc/index.md b/doc/index.md index 0234b8fbf5..a065b95385 100644 --- a/doc/index.md +++ b/doc/index.md @@ -332,4 +332,4 @@ Note that this table only lists those exceptions thrown due to the type. For ins @author [Niels Lohmann](http://nlohmann.me) @see https://github.com/nlohmann/json to download the source code -@version 3.10.2 +@version 3.10.3 diff --git a/doc/json.gif b/doc/json.gif index 56d5bc02d4..68f37e7430 100644 Binary files a/doc/json.gif and b/doc/json.gif differ diff --git a/doc/mkdocs/docs/integration/package_managers.md b/doc/mkdocs/docs/integration/package_managers.md index aba070984c..a4eda83f69 100644 --- a/doc/mkdocs/docs/integration/package_managers.md +++ b/doc/mkdocs/docs/integration/package_managers.md @@ -160,7 +160,11 @@ If you are using [conda](https://conda.io/), you can use the package [nlohmann_j ## MSYS2 -If you are using [MSYS2](http://www.msys2.org/), your can use the [mingw-w64-nlohmann-json](https://packages.msys2.org/base/mingw-w64-nlohmann-json) package, just type `pacman -S mingw-w64-i686-nlohmann-json` or `pacman -S mingw-w64-x86_64-nlohmann-json` for installation. Please file issues [here](https://github.com/msys2/MINGW-packages/issues/new?title=%5Bnlohmann-json%5D) if you experience problems with the packages. +If you are using [MSYS2](http://www.msys2.org/), you can use the [mingw-w64-nlohmann-json](https://packages.msys2.org/base/mingw-w64-nlohmann-json) package, just type `pacman -S mingw-w64-i686-nlohmann-json` or `pacman -S mingw-w64-x86_64-nlohmann-json` for installation. Please file issues [here](https://github.com/msys2/MINGW-packages/issues/new?title=%5Bnlohmann-json%5D) if you experience problems with the packages. + +## MacPorts + +If you are using [MacPorts](https://ports.macports.org), execute `sudo port install nlohmann-json` to install the [nlohmann-json](https://ports.macports.org/port/nlohmann-json/) package. ## build2 diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 76a0dc62cf..c2a65bdda6 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -1,7 +1,8 @@ #pragma once -#include // pair +#include // declval, pair #include +#include // This file contains all internal macro definitions // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them @@ -292,6 +293,45 @@ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +// inspired from https://stackoverflow.com/a/26745591 +// allows to call any std function as if (e.g. with begin): +// using std::begin; begin(x); +// +// it allows using the detected idiom to retrieve the return type +// of such an expression +#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ + namespace detail { \ + using std::std_name; \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + } \ + \ + namespace detail2 { \ + struct std_name##_tag \ + { \ + }; \ + \ + template \ + std_name##_tag std_name(T&&...); \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + \ + template \ + struct would_call_std_##std_name \ + { \ + static constexpr auto const value = ::nlohmann::detail:: \ + is_detected_exact::value; \ + }; \ + } /* namespace detail2 */ \ + \ + template \ + struct would_call_std_##std_name : detail2::would_call_std_##std_name \ + { \ + } + #ifndef JSON_USE_IMPLICIT_CONVERSIONS #define JSON_USE_IMPLICIT_CONVERSIONS 1 #endif diff --git a/include/nlohmann/detail/macro_unscope.hpp b/include/nlohmann/detail/macro_unscope.hpp index 3f56e4b85e..67bf1466bc 100644 --- a/include/nlohmann/detail/macro_unscope.hpp +++ b/include/nlohmann/detail/macro_unscope.hpp @@ -19,5 +19,6 @@ #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef JSON_EXPLICIT +#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL #include diff --git a/include/nlohmann/detail/meta/call_std/begin.hpp b/include/nlohmann/detail/meta/call_std/begin.hpp new file mode 100644 index 0000000000..da937144c8 --- /dev/null +++ b/include/nlohmann/detail/meta/call_std/begin.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace nlohmann +{ +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/call_std/end.hpp b/include/nlohmann/detail/meta/call_std/end.hpp new file mode 100644 index 0000000000..1909007398 --- /dev/null +++ b/include/nlohmann/detail/meta/call_std/end.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace nlohmann +{ +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); +} // namespace nlohmann diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index ede55acc26..ca6051e7cd 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -5,8 +5,11 @@ #include // declval #include // tuple -#include #include + +#include +#include +#include #include #include #include @@ -79,9 +82,6 @@ using reference_t = typename T::reference; template using iterator_category_t = typename T::iterator_category; -template -using iterator_t = typename T::iterator; - template using to_json_function = decltype(T::to_json(std::declval()...)); @@ -217,6 +217,31 @@ struct is_iterator_traits> is_detected::value; }; +template +struct is_range +{ + private: + using t_ref = typename std::add_lvalue_reference::type; + + using iterator = detected_t; + using sentinel = detected_t; + + // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator + // and https://en.cppreference.com/w/cpp/iterator/sentinel_for + // but reimplementing these would be too much work, as a lot of other concepts are used underneath + static constexpr auto is_iterator_begin = + is_iterator_traits>::value; + + public: + static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; +}; + +template +using iterator_t = enable_if_t::value, result_of_begin())>>; + +template +using range_value_t = value_type_t>>; + // The following implementation of is_complete_type is taken from // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ // and is written by Xiang Fan who agreed to using it in this library. @@ -291,8 +316,9 @@ struct is_compatible_string_type_impl : std::false_type {}; template struct is_compatible_string_type_impl < BasicJsonType, CompatibleStringType, - enable_if_t::value >> + enable_if_t::value >> { static constexpr auto value = is_constructible::value; @@ -327,17 +353,13 @@ struct is_compatible_array_type_impl : std::false_type {}; template struct is_compatible_array_type_impl < BasicJsonType, CompatibleArrayType, - enable_if_t < is_detected::value&& + enable_if_t < is_detected::value&& -// This is needed because json_reverse_iterator has a ::iterator type... -// Therefore it is detected as a CompatibleArrayType. -// The real fix would be to have an Iterable concept. - !is_iterator_traits < - iterator_traits>::value >> + is_iterator_traits>>::value >> { static constexpr bool value = is_constructible::value; + range_value_t>::value; }; template @@ -359,28 +381,26 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t < !std::is_same::value&& + !is_compatible_string_type::value&& is_default_constructible::value&& (std::is_move_assignable::value || std::is_copy_assignable::value)&& -is_detected::value&& is_detected::value&& +is_iterator_traits>>::value&& +is_detected::value&& is_complete_type < -detected_t>::value >> +detected_t>::value >> { + using value_type = range_value_t; + static constexpr bool value = - // This is needed because json_reverse_iterator has a ::iterator type, - // furthermore, std::back_insert_iterator (and other iterators) have a - // base class `iterator`... Therefore it is detected as a - // ConstructibleArrayType. The real fix would be to have an Iterable - // concept. - !is_iterator_traits>::value && - - (std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, typename ConstructibleArrayType::value_type >::value); + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; }; template diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp index 6f2462685e..1cad57b19a 100644 --- a/include/nlohmann/detail/output/output_adapters.hpp +++ b/include/nlohmann/detail/output/output_adapters.hpp @@ -37,11 +37,11 @@ template using output_adapter_t = std::shared_ptr>; /// output adapter for byte vectors -template +template> class output_vector_adapter : public output_adapter_protocol { public: - explicit output_vector_adapter(std::vector& vec) noexcept + explicit output_vector_adapter(std::vector& vec) noexcept : v(vec) {} @@ -57,7 +57,7 @@ class output_vector_adapter : public output_adapter_protocol } private: - std::vector& v; + std::vector& v; }; #ifndef JSON_NO_IO @@ -114,8 +114,9 @@ template> class output_adapter { public: - output_adapter(std::vector& vec) - : oa(std::make_shared>(vec)) {} + template> + output_adapter(std::vector& vec) + : oa(std::make_shared>(vec)) {} #ifndef JSON_NO_IO output_adapter(std::basic_ostream& s) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index fc3e608283..b140577f2c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -32,7 +32,7 @@ SOFTWARE. #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 2 +#define NLOHMANN_JSON_VERSION_PATCH 3 #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t @@ -1065,7 +1065,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.2", basic_json())); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.3", basic_json())); // LCOV_EXCL_LINE } break; } @@ -3695,15 +3695,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (idx >= m_value.array->size()) { #if JSON_DIAGNOSTICS - // remember array size before resizing - const auto previous_size = m_value.array->size(); + // remember array size & capacity before resizing + const auto old_size = m_value.array->size(); + const auto old_capacity = m_value.array->capacity(); #endif m_value.array->resize(idx + 1); #if JSON_DIAGNOSTICS - // set parent for values added above - set_parents(begin() + static_cast(previous_size), static_cast(idx + 1 - previous_size)); + if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity)) + { + // capacity has changed: update all parents + set_parents(); + } + else + { + // set parent for values added above + set_parents(begin() + static_cast(old_size), static_cast(idx + 1 - old_size)); + } #endif + assert_invariant(); } return m_value.array->operator[](idx); @@ -6009,6 +6019,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (auto it = j.cbegin(); it != j.cend(); ++it) { m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif } } @@ -6069,6 +6082,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (auto it = first; it != last; ++it) { m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif } } diff --git a/meson.build b/meson.build index 4c2e08053b..44ad088fe3 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('nlohmann_json', 'cpp', - version : '3.10.2', + version : '3.10.3', license : 'MIT', ) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8959265dae..25c6983b04 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -32,7 +32,7 @@ SOFTWARE. #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 2 +#define NLOHMANN_JSON_VERSION_PATCH 3 #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t @@ -167,7 +167,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept // #include -#include // pair +#include // declval, pair // #include @@ -2214,6 +2214,83 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ +// #include + + +#include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + + +// https://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template class Op, class... Args> +using is_detected = typename detector::value_t; + +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; + +template class Op, class... Args> +using detected_t = typename detector::type; + +template class Op, class... Args> +using detected_or = detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; +} // namespace detail +} // namespace nlohmann + // This file contains all internal macro definitions // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them @@ -2504,6 +2581,45 @@ JSON_HEDLEY_DIAGNOSTIC_POP inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +// inspired from https://stackoverflow.com/a/26745591 +// allows to call any std function as if (e.g. with begin): +// using std::begin; begin(x); +// +// it allows using the detected idiom to retrieve the return type +// of such an expression +#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ + namespace detail { \ + using std::std_name; \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + } \ + \ + namespace detail2 { \ + struct std_name##_tag \ + { \ + }; \ + \ + template \ + std_name##_tag std_name(T&&...); \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + \ + template \ + struct would_call_std_##std_name \ + { \ + static constexpr auto const value = ::nlohmann::detail:: \ + is_detected_exact::value; \ + }; \ + } /* namespace detail2 */ \ + \ + template \ + struct would_call_std_##std_name : detail2::would_call_std_##std_name \ + { \ + } + #ifndef JSON_USE_IMPLICIT_CONVERSIONS #define JSON_USE_IMPLICIT_CONVERSIONS 1 #endif @@ -3207,6 +3323,9 @@ template struct identity_tag {}; #include // declval #include // tuple +// #include + + // #include @@ -3214,19 +3333,6 @@ template struct identity_tag {}; // #include - -namespace nlohmann -{ -namespace detail -{ -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; -} // namespace detail -} // namespace nlohmann - // #include @@ -3275,73 +3381,31 @@ struct iterator_traits::value>> } // namespace detail } // namespace nlohmann -// #include - -// #include - -// #include - +// #include -#include -// #include +// #include -// https://en.cppreference.com/w/cpp/experimental/is_detected namespace nlohmann { -namespace detail -{ -struct nonesuch -{ - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - nonesuch(nonesuch const&&) = delete; - void operator=(nonesuch const&) = delete; - void operator=(nonesuch&&) = delete; -}; - -template class Op, - class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); +} // namespace nlohmann -template class Op, class... Args> -using is_detected = typename detector::value_t; +// #include -template class Op, class... Args> -struct is_detected_lazy : is_detected { }; -template class Op, class... Args> -using detected_t = typename detector::type; +// #include -template class Op, class... Args> -using detected_or = detector; -template class Op, class... Args> -using detected_or_t = typename detected_or::type; +namespace nlohmann +{ +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); +} // namespace nlohmann -template class Op, class... Args> -using is_detected_exact = std::is_same>; +// #include -template class Op, class... Args> -using is_detected_convertible = - std::is_convertible, To>; -} // namespace detail -} // namespace nlohmann +// #include // #include #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ @@ -3492,9 +3556,6 @@ using reference_t = typename T::reference; template using iterator_category_t = typename T::iterator_category; -template -using iterator_t = typename T::iterator; - template using to_json_function = decltype(T::to_json(std::declval()...)); @@ -3630,6 +3691,31 @@ struct is_iterator_traits> is_detected::value; }; +template +struct is_range +{ + private: + using t_ref = typename std::add_lvalue_reference::type; + + using iterator = detected_t; + using sentinel = detected_t; + + // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator + // and https://en.cppreference.com/w/cpp/iterator/sentinel_for + // but reimplementing these would be too much work, as a lot of other concepts are used underneath + static constexpr auto is_iterator_begin = + is_iterator_traits>::value; + + public: + static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; +}; + +template +using iterator_t = enable_if_t::value, result_of_begin())>>; + +template +using range_value_t = value_type_t>>; + // The following implementation of is_complete_type is taken from // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ // and is written by Xiang Fan who agreed to using it in this library. @@ -3704,8 +3790,9 @@ struct is_compatible_string_type_impl : std::false_type {}; template struct is_compatible_string_type_impl < BasicJsonType, CompatibleStringType, - enable_if_t::value >> + enable_if_t::value >> { static constexpr auto value = is_constructible::value; @@ -3740,17 +3827,13 @@ struct is_compatible_array_type_impl : std::false_type {}; template struct is_compatible_array_type_impl < BasicJsonType, CompatibleArrayType, - enable_if_t < is_detected::value&& + enable_if_t < is_detected::value&& -// This is needed because json_reverse_iterator has a ::iterator type... -// Therefore it is detected as a CompatibleArrayType. -// The real fix would be to have an Iterable concept. - !is_iterator_traits < - iterator_traits>::value >> + is_iterator_traits>>::value >> { static constexpr bool value = is_constructible::value; + range_value_t>::value; }; template @@ -3772,28 +3855,26 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t < !std::is_same::value&& + !is_compatible_string_type::value&& is_default_constructible::value&& (std::is_move_assignable::value || std::is_copy_assignable::value)&& -is_detected::value&& is_detected::value&& +is_iterator_traits>>::value&& +is_detected::value&& is_complete_type < -detected_t>::value >> +detected_t>::value >> { + using value_type = range_value_t; + static constexpr bool value = - // This is needed because json_reverse_iterator has a ::iterator type, - // furthermore, std::back_insert_iterator (and other iterators) have a - // base class `iterator`... Therefore it is detected as a - // ConstructibleArrayType. The real fix would be to have an Iterable - // concept. - !is_iterator_traits>::value && - - (std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, typename ConstructibleArrayType::value_type >::value); + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; }; template @@ -13485,11 +13566,11 @@ template using output_adapter_t = std::shared_ptr>; /// output adapter for byte vectors -template +template> class output_vector_adapter : public output_adapter_protocol { public: - explicit output_vector_adapter(std::vector& vec) noexcept + explicit output_vector_adapter(std::vector& vec) noexcept : v(vec) {} @@ -13505,7 +13586,7 @@ class output_vector_adapter : public output_adapter_protocol } private: - std::vector& v; + std::vector& v; }; #ifndef JSON_NO_IO @@ -13562,8 +13643,9 @@ template> class output_adapter { public: - output_adapter(std::vector& vec) - : oa(std::make_shared>(vec)) {} + template> + output_adapter(std::vector& vec) + : oa(std::make_shared>(vec)) {} #ifndef JSON_NO_IO output_adapter(std::basic_ostream& s) @@ -18470,7 +18552,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.2", basic_json())); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.3", basic_json())); // LCOV_EXCL_LINE } break; } @@ -21100,15 +21182,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (idx >= m_value.array->size()) { #if JSON_DIAGNOSTICS - // remember array size before resizing - const auto previous_size = m_value.array->size(); + // remember array size & capacity before resizing + const auto old_size = m_value.array->size(); + const auto old_capacity = m_value.array->capacity(); #endif m_value.array->resize(idx + 1); #if JSON_DIAGNOSTICS - // set parent for values added above - set_parents(begin() + static_cast(previous_size), static_cast(idx + 1 - previous_size)); + if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity)) + { + // capacity has changed: update all parents + set_parents(); + } + else + { + // set parent for values added above + set_parents(begin() + static_cast(old_size), static_cast(idx + 1 - old_size)); + } #endif + assert_invariant(); } return m_value.array->operator[](idx); @@ -23414,6 +23506,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (auto it = j.cbegin(); it != j.cend(); ++it) { m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif } } @@ -23474,6 +23569,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (auto it = first; it != last; ++it) { m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif } } @@ -26482,6 +26580,7 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef JSON_EXPLICIT +#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL // #include diff --git a/test/src/fuzzer-driver_afl.cpp b/test/src/fuzzer-driver_afl.cpp index 5cb65dfaf1..83d60b0596 100644 --- a/test/src/fuzzer-driver_afl.cpp +++ b/test/src/fuzzer-driver_afl.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a driver for American Fuzzy Lop (afl-fuzz). It relies on diff --git a/test/src/fuzzer-parse_bson.cpp b/test/src/fuzzer-parse_bson.cpp index ec3214fda0..4ff5fdc1ed 100644 --- a/test/src/fuzzer-parse_bson.cpp +++ b/test/src/fuzzer-parse_bson.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a parser test suitable for fuzz testing. Given a byte diff --git a/test/src/fuzzer-parse_cbor.cpp b/test/src/fuzzer-parse_cbor.cpp index bb4018577b..7d7857e0e3 100644 --- a/test/src/fuzzer-parse_cbor.cpp +++ b/test/src/fuzzer-parse_cbor.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a parser test suitable for fuzz testing. Given a byte diff --git a/test/src/fuzzer-parse_json.cpp b/test/src/fuzzer-parse_json.cpp index 6002b7a3a2..aacf582ee3 100644 --- a/test/src/fuzzer-parse_json.cpp +++ b/test/src/fuzzer-parse_json.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a parser test suitable for fuzz testing. Given a byte diff --git a/test/src/fuzzer-parse_msgpack.cpp b/test/src/fuzzer-parse_msgpack.cpp index 418e7d5583..5485a9e087 100644 --- a/test/src/fuzzer-parse_msgpack.cpp +++ b/test/src/fuzzer-parse_msgpack.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a parser test suitable for fuzz testing. Given a byte diff --git a/test/src/fuzzer-parse_ubjson.cpp b/test/src/fuzzer-parse_ubjson.cpp index 9540ded02b..fc6fc7136c 100644 --- a/test/src/fuzzer-parse_ubjson.cpp +++ b/test/src/fuzzer-parse_ubjson.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json This file implements a parser test suitable for fuzz testing. Given a byte diff --git a/test/src/unit-algorithms.cpp b/test/src/unit-algorithms.cpp index ff1c28996f..78f7fa1957 100644 --- a/test/src/unit-algorithms.cpp +++ b/test/src/unit-algorithms.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-allocator.cpp b/test/src/unit-allocator.cpp index 16eed50db5..d42f02cfda 100644 --- a/test/src/unit-allocator.cpp +++ b/test/src/unit-allocator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-alt-string.cpp b/test/src/unit-alt-string.cpp index 4a580412d5..d06fb51905 100644 --- a/test/src/unit-alt-string.cpp +++ b/test/src/unit-alt-string.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-assert_macro.cpp b/test/src/unit-assert_macro.cpp index a76fb5c226..8bedcf8639 100644 --- a/test/src/unit-assert_macro.cpp +++ b/test/src/unit-assert_macro.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-bson.cpp b/test/src/unit-bson.cpp index 8c85ec5427..91a7603409 100644 --- a/test/src/unit-bson.cpp +++ b/test/src/unit-bson.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-byte_container_with_subtype.cpp b/test/src/unit-byte_container_with_subtype.cpp index 49e6f2ceb5..17ce390706 100644 --- a/test/src/unit-byte_container_with_subtype.cpp +++ b/test/src/unit-byte_container_with_subtype.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-capacity.cpp b/test/src/unit-capacity.cpp index aaf58fcf83..87baff8a81 100644 --- a/test/src/unit-capacity.cpp +++ b/test/src/unit-capacity.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 1f24acc87e..30f47b0f61 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_const_iterator.cpp b/test/src/unit-class_const_iterator.cpp index e520f9d6f8..108162bde7 100644 --- a/test/src/unit-class_const_iterator.cpp +++ b/test/src/unit-class_const_iterator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_iterator.cpp b/test/src/unit-class_iterator.cpp index d32854f6d7..9c6a5d4d8b 100644 --- a/test/src/unit-class_iterator.cpp +++ b/test/src/unit-class_iterator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_lexer.cpp b/test/src/unit-class_lexer.cpp index 42fc738242..d05066a973 100644 --- a/test/src/unit-class_lexer.cpp +++ b/test/src/unit-class_lexer.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index 108c1ad707..ddd4099415 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-comparison.cpp b/test/src/unit-comparison.cpp index 5952fc032c..622a122727 100644 --- a/test/src/unit-comparison.cpp +++ b/test/src/unit-comparison.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-concepts.cpp b/test/src/unit-concepts.cpp index 6be58de1b7..147d3f341c 100644 --- a/test/src/unit-concepts.cpp +++ b/test/src/unit-concepts.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 8499d32271..15f92e725d 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-constructor2.cpp b/test/src/unit-constructor2.cpp index e50f25c931..3bece48ebf 100644 --- a/test/src/unit-constructor2.cpp +++ b/test/src/unit-constructor2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-convenience.cpp b/test/src/unit-convenience.cpp index 6437bae09e..b0d865c6a1 100644 --- a/test/src/unit-convenience.cpp +++ b/test/src/unit-convenience.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 099c2bd488..bd7d6c489a 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index b9f2dd4b88..3d61952884 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-diagnostics.cpp b/test/src/unit-diagnostics.cpp index d4bbf93aa5..a0bcceb279 100644 --- a/test/src/unit-diagnostics.cpp +++ b/test/src/unit-diagnostics.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -184,4 +184,71 @@ TEST_CASE("Better diagnostics") j["second"] = value; j2["something"] = j; } + + SECTION("Regression test for issue #3007 - Parent pointers properly set when using update()") + { + // void update(const_reference j) + { + json j = json::object(); + + { + json j2 = json::object(); + j2["one"] = 1; + + j.update(j2); + } + + // Must call operator[] on const element, otherwise m_parent gets updated. + auto const& constJ = j; + CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error); + } + + // void update(const_iterator first, const_iterator last) + { + json j = json::object(); + + { + json j2 = json::object(); + j2["one"] = 1; + + j.update(j2.begin(), j2.end()); + } + + // Must call operator[] on const element, otherwise m_parent gets updated. + auto const& constJ = j; + CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error); + } + + // Code from #3007 triggering unwanted assertion without fix to update(). + { + json root = json::array(); + json lower = json::object(); + + { + json lowest = json::object(); + lowest["one"] = 1; + + lower.update(lowest); + } + + root.push_back(lower); + } + } + + SECTION("Regression test for https://github.com/nlohmann/json/issues/3032") + { + // reference operator[](size_type idx) + { + json j_arr = json::array(); + j_arr[0] = 0; + j_arr[1] = 1; + j_arr[2] = 2; + j_arr[3] = 3; + j_arr[4] = 4; + j_arr[5] = 5; + j_arr[6] = 6; + j_arr[7] = 7; + json j_arr_copy = j_arr; + } + } } diff --git a/test/src/unit-disabled_exceptions.cpp b/test/src/unit-disabled_exceptions.cpp index 85bf484724..98b5f579cb 100644 --- a/test/src/unit-disabled_exceptions.cpp +++ b/test/src/unit-disabled_exceptions.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-element_access1.cpp b/test/src/unit-element_access1.cpp index 92ffcb35bf..e909a30cb2 100644 --- a/test/src/unit-element_access1.cpp +++ b/test/src/unit-element_access1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-element_access2.cpp b/test/src/unit-element_access2.cpp index 5da944c313..dc6fe86466 100644 --- a/test/src/unit-element_access2.cpp +++ b/test/src/unit-element_access2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-hash.cpp b/test/src/unit-hash.cpp index 9a73485f32..73fb898a9f 100644 --- a/test/src/unit-hash.cpp +++ b/test/src/unit-hash.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-inspection.cpp b/test/src/unit-inspection.cpp index 0210c4bce2..c07a4b9f94 100644 --- a/test/src/unit-inspection.cpp +++ b/test/src/unit-inspection.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-items.cpp b/test/src/unit-items.cpp index b96726f9ff..a4e2aa12af 100644 --- a/test/src/unit-items.cpp +++ b/test/src/unit-items.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-iterators1.cpp b/test/src/unit-iterators1.cpp index b11a967d32..314084e493 100644 --- a/test/src/unit-iterators1.cpp +++ b/test/src/unit-iterators1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-iterators2.cpp b/test/src/unit-iterators2.cpp index f25b1862b4..1c16042acb 100644 --- a/test/src/unit-iterators2.cpp +++ b/test/src/unit-iterators2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-json_patch.cpp b/test/src/unit-json_patch.cpp index 4365433ed7..1a8c9c4448 100644 --- a/test/src/unit-json_patch.cpp +++ b/test/src/unit-json_patch.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index 410e5ff2af..5efd96c0e5 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-large_json.cpp b/test/src/unit-large_json.cpp index 3d06015e52..570da277c1 100644 --- a/test/src/unit-large_json.cpp +++ b/test/src/unit-large_json.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-merge_patch.cpp b/test/src/unit-merge_patch.cpp index 34a633ef21..3080b2a638 100644 --- a/test/src/unit-merge_patch.cpp +++ b/test/src/unit-merge_patch.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-meta.cpp b/test/src/unit-meta.cpp index da0d5b4a13..5624016085 100644 --- a/test/src/unit-meta.cpp +++ b/test/src/unit-meta.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -43,10 +43,10 @@ TEST_CASE("version information") CHECK(j["url"] == "https://github.com/nlohmann/json"); CHECK(j["version"] == json( { - {"string", "3.10.2"}, + {"string", "3.10.3"}, {"major", 3}, {"minor", 10}, - {"patch", 2} + {"patch", 3} })); CHECK(j.find("platform") != j.end()); diff --git a/test/src/unit-modifiers.cpp b/test/src/unit-modifiers.cpp index 72d06cafe3..1fb922a6b2 100644 --- a/test/src/unit-modifiers.cpp +++ b/test/src/unit-modifiers.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index 2c973d441b..75cc01dda7 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index 3e376ad0a0..b81f8cdde8 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-ordered_json.cpp b/test/src/unit-ordered_json.cpp index b43b02673f..a38fe6ae05 100644 --- a/test/src/unit-ordered_json.cpp +++ b/test/src/unit-ordered_json.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-ordered_map.cpp b/test/src/unit-ordered_map.cpp index ae2fdd1740..7283b726f1 100644 --- a/test/src/unit-ordered_map.cpp +++ b/test/src/unit-ordered_map.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-pointer_access.cpp b/test/src/unit-pointer_access.cpp index 8b7dc5526b..492e6cb7c5 100644 --- a/test/src/unit-pointer_access.cpp +++ b/test/src/unit-pointer_access.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 9666c55fec..ab7fb4a733 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index eee9af1ecb..cdca8af58e 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-regression1.cpp b/test/src/unit-regression1.cpp index 6f7758432a..f5f715c60a 100644 --- a/test/src/unit-regression1.cpp +++ b/test/src/unit-regression1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index 8d0175e9d7..cf74297825 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -181,6 +181,13 @@ class sax_no_exception : public nlohmann::detail::json_sax_dom_parser std::string* sax_no_exception::error_string = nullptr; +///////////////////////////////////////////////////////////////////// +// for #2982 +///////////////////////////////////////////////////////////////////// + +template +class my_allocator : public std::allocator +{}; TEST_CASE("regression tests 2") { @@ -679,6 +686,15 @@ TEST_CASE("regression tests 2") test3[json::json_pointer(p)] = json::object(); CHECK(test3.dump() == "{\"/root\":{}}"); } + + SECTION("issue #2982 - to_{binary format} does not provide a mechanism for specifying a custom allocator for the returned type") + { + std::vector> my_vector; + json j = {1, 2, 3, 4}; + json::to_cbor(j, my_vector); + json k = json::from_cbor(my_vector); + CHECK(j == k); + } } DOCTEST_CLANG_SUPPRESS_WARNING_POP diff --git a/test/src/unit-serialization.cpp b/test/src/unit-serialization.cpp index d2038c50cb..efa4d494da 100644 --- a/test/src/unit-serialization.cpp +++ b/test/src/unit-serialization.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 74e0bfc1de..4778735026 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-to_chars.cpp b/test/src/unit-to_chars.cpp index 45beb9d12d..abc3623a01 100644 --- a/test/src/unit-to_chars.cpp +++ b/test/src/unit-to_chars.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-ubjson.cpp b/test/src/unit-ubjson.cpp index 0bec405900..f196357d85 100644 --- a/test/src/unit-ubjson.cpp +++ b/test/src/unit-ubjson.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index f83ef9a0ac..0172b53ec4 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -850,4 +850,34 @@ TEST_CASE("Issue #1237") static_assert(!std::is_convertible::value, ""); } +namespace +{ +class no_iterator_type +{ + public: + no_iterator_type(std::initializer_list l) + : _v(l) + {} + + std::vector::const_iterator begin() const + { + return _v.begin(); + } + + std::vector::const_iterator end() const + { + return _v.end(); + } + + private: + std::vector _v; +}; +} // namespace + +TEST_CASE("compatible array type, without iterator type alias") +{ + no_iterator_type vec{1, 2, 3}; + json j = vec; +} + DOCTEST_GCC_SUPPRESS_WARNING_POP diff --git a/test/src/unit-udt_macro.cpp b/test/src/unit-udt_macro.cpp index 30188fb3f7..18385ee502 100644 --- a/test/src/unit-udt_macro.cpp +++ b/test/src/unit-udt_macro.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode1.cpp b/test/src/unit-unicode1.cpp index 9f15dff38d..c5fd1c13c8 100644 --- a/test/src/unit-unicode1.cpp +++ b/test/src/unit-unicode1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode2.cpp b/test/src/unit-unicode2.cpp index c88da22d9b..6418fbd71c 100644 --- a/test/src/unit-unicode2.cpp +++ b/test/src/unit-unicode2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode3.cpp b/test/src/unit-unicode3.cpp index 2a48b20954..0d9ec58190 100644 --- a/test/src/unit-unicode3.cpp +++ b/test/src/unit-unicode3.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode4.cpp b/test/src/unit-unicode4.cpp index 1f4b37410c..7babc589d8 100644 --- a/test/src/unit-unicode4.cpp +++ b/test/src/unit-unicode4.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode5.cpp b/test/src/unit-unicode5.cpp index 9273a741a0..e911872e24 100644 --- a/test/src/unit-unicode5.cpp +++ b/test/src/unit-unicode5.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-user_defined_input.cpp b/test/src/unit-user_defined_input.cpp index 711236c299..eb3005ffa5 100644 --- a/test/src/unit-user_defined_input.cpp +++ b/test/src/unit-user_defined_input.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-wstring.cpp b/test/src/unit-wstring.cpp index 9d0592087d..145b5070f6 100644 --- a/test/src/unit-wstring.cpp +++ b/test/src/unit-wstring.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit.cpp b/test/src/unit.cpp index 98e40c8488..dbacdc262b 100644 --- a/test/src/unit.cpp +++ b/test/src/unit.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 3.10.2 +| | |__ | | | | | | version 3.10.3 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/wsjcpp.yml b/wsjcpp.yml index 6c1a20bbe4..d2ee48c433 100644 --- a/wsjcpp.yml +++ b/wsjcpp.yml @@ -2,7 +2,7 @@ wsjcpp_version: "v0.1.1" cmake_minimum_required: "3.0" cmake_cxx_standard: "11" name: "nlohmann/json" -version: "v3.10.2" +version: "v3.10.3" description: "JSON for Modern C++" issues: "https://github.com/nlohmann/json/issues" keywords: