From 19437c15de2dae59615576c3303284b691f3678c Mon Sep 17 00:00:00 2001 From: DmitryKuk Date: Sat, 5 Aug 2017 10:43:08 +0300 Subject: [PATCH 01/36] massage -> message --- src/json.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index c22cce4f..e20ab71d 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -215,7 +215,7 @@ file. Exceptions have ids 1xx. -name / id | example massage | description +name / id | example message | description ------------------------------ | --------------- | ------------------------- json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. @@ -272,7 +272,7 @@ class parse_error : public exception Exceptions have ids 2xx. -name / id | example massage | description +name / id | example message | description ----------------------------------- | --------------- | ------------------------- json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. From ab44a50d984aeec2819230e3ce1b9a9cb0867ee0 Mon Sep 17 00:00:00 2001 From: traits Date: Mon, 7 Aug 2017 14:23:48 +0200 Subject: [PATCH 02/36] Digraph warning The original version can trigger a digraph-related warning in VS2015. Is this namespace construct a typo or something deliberate? --- src/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json.hpp b/src/json.hpp index e20ab71d..9a04a62b 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -14492,7 +14492,7 @@ struct hash /// specialization for std::less template<> -struct less<::nlohmann::detail::value_t> +struct less { /*! @brief compare two value_t enum values From 054b0250bef229534299b3e3b1bde6175b4b3cfc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 8 Aug 2017 19:14:22 +0200 Subject: [PATCH 03/36] :construction_worker: trying to install g++ to make clang work --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 530ef434..271673cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -216,6 +216,10 @@ matrix: - os: linux env: LLVM_VERSION=3.7.0 compiler: clang + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-7 - os: linux env: LLVM_VERSION=3.7.1 From c90bf5e0f1c5d08f081ff98a17ca2cedbf6e7f37 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 8 Aug 2017 21:26:15 +0200 Subject: [PATCH 04/36] :construction_worker: removed failing builders --- .travis.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 271673cb..b3d1677d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -213,17 +213,13 @@ matrix: env: LLVM_VERSION=3.6.2 compiler: clang - - os: linux - env: LLVM_VERSION=3.7.0 - compiler: clang - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-7 +# - os: linux +# env: LLVM_VERSION=3.7.0 +# compiler: clang - - os: linux - env: LLVM_VERSION=3.7.1 - compiler: clang +# - os: linux +# env: LLVM_VERSION=3.7.1 +# compiler: clang - os: linux env: LLVM_VERSION=3.8.0 From 4b55f0ebd6c95e61364a29caae9743aed30b5d93 Mon Sep 17 00:00:00 2001 From: Kyle Thompson Date: Tue, 8 Aug 2017 18:43:03 -0400 Subject: [PATCH 05/36] To fix compilation issue for intel OSX compiler o To prevent the compilation issue on OSX with the intel compiler suite. The error was found with icpc version 15.0.3.187 where the "__clang_version__" was not defined correctly, while "__clang__" was. --- src/json.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index e20ab71d..5bb8b31a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -7526,10 +7526,10 @@ class basic_json result["platform"] = "unknown"; #endif -#if defined(__clang__) - result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; -#elif defined(__ICC) || defined(__INTEL_COMPILER) +#if defined(__ICC) || defined(__INTEL_COMPILER) result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; +#elif defined(__clang__) + result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; #elif defined(__GNUC__) || defined(__GNUG__) result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}}; #elif defined(__HP_cc) || defined(__HP_aCC) From 86b3d06a93927b7d52b8ae217c9f37ea593669ce Mon Sep 17 00:00:00 2001 From: Markus Werle Date: Wed, 9 Aug 2017 11:56:48 +0200 Subject: [PATCH 06/36] remove duplicate word s/to to/to/ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14d9deaf..afaac3aa 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ json j_umset(c_umset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] ``` -Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON types (see examples above) can be used to to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container. +Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON types (see examples above) can be used to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container. ```cpp std::map c_map { {"one", 1}, {"two", 2}, {"three", 3} }; From c9509ccf9774de0d0c6c9de51f95508568c25ac8 Mon Sep 17 00:00:00 2001 From: WebProdPP Date: Wed, 9 Aug 2017 16:13:43 +0300 Subject: [PATCH 07/36] Update json.hpp mistake --- src/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json.hpp b/src/json.hpp index 5bb8b31a..5e352c8f 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -12058,7 +12058,7 @@ class basic_json // passed iterators must belong to objects if (JSON_UNLIKELY(not first.m_object->is_object() - or not first.m_object->is_object())) + or not last.m_object->is_object())) { JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects")); } From 99ea12f3047b2dc3189f210f47dc7cac13b4958b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 06:50:34 +0200 Subject: [PATCH 08/36] :memo: acknowledgements for #674, #678, #682, #685, and #686 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index afaac3aa..fcfe58ca 100644 --- a/README.md +++ b/README.md @@ -854,6 +854,11 @@ I deeply appreciate the help of the following people. - [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `` with ``. - [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library. - [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists. +- [Greg Hurrell](https://github.com/wincent) fixed a typo. +- [Dmitry Kukovinets](https://github.com/DmitryKuk) fixed a typo. +- [kbthomp1](https://github.com/kbthomp1) fixed an issue related to the Intel OSX compiler. +- [Markus Werle](https://github.com/daixtrose) fixed a typo. +- [WebProdPP](https://github.com/WebProdPP) fixed a subtle error in a precondition check. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. From 54c67dcfec158324201a8db84a423e2ba3b7c507 Mon Sep 17 00:00:00 2001 From: traits Date: Thu, 10 Aug 2017 09:05:00 +0200 Subject: [PATCH 09/36] Update json.hpp --- src/json.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/json.hpp b/src/json.hpp index 9a04a62b..efd76da7 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -14492,7 +14492,8 @@ struct hash /// specialization for std::less template<> -struct less +struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', + // see https://github.com/nlohmann/json/pull/679 { /*! @brief compare two value_t enum values From c1642affaa0fdb8112409f4ce0addaa3457a4ee1 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:03:35 +0200 Subject: [PATCH 10/36] :construction_worker: clang-3.8 --- .travis.yml | 291 ++-------------------------------------------------- 1 file changed, 6 insertions(+), 285 deletions(-) diff --git a/.travis.yml b/.travis.yml index b3d1677d..775235c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,293 +28,22 @@ env: matrix: include: - # Valgrind - - os: linux compiler: gcc - env: - - COMPILER=g++-4.9 - - SPECIAL=valgrind + env: COMPILER=clang-3.8 addons: apt: - sources: ['ubuntu-toolchain-r-test'] - packages: [g++-4.9, valgrind] - after_success: - - make check TEST_PREFIX="valgrind --error-exitcode=1 --leak-check=full " TEST_PATTERN="" - - # cLang sanitizer - # note: sadly clang's libc++ has errors when running with sanitize, - # so we use clang with gcc's libstdc++ which doesn't give those error. - # that's why we need to install g++-6 to get the lastest version - - os: linux - env: - - LLVM_VERSION=3.8.1 - - SPECIAL=sanitizer - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-6 - compiler: clang - before_script: - - make clang_sanitize - - # cppcheck - - - os: linux - compiler: gcc - env: - - COMPILER=g++-4.9 - - SPECIAL=cppcheck - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: [g++-4.9, cppcheck] - after_success: - - make cppcheck - - # no exceptions - - - os: linux - compiler: gcc - env: - - COMPILER=g++-4.9 - - SPECIAL=no_exceptions - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: [g++-4.9, cppcheck] - after_success: - - make clean - - CPPFLAGS="-DJSON_NOEXCEPTION" make check TEST_PATTERN="-e \"*\"" - - # Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/) - - - os: linux - compiler: gcc - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-4.9', 'ruby'] - before_script: - - wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz - - tar xf lcov_1.11.orig.tar.gz - - sudo make -C lcov-1.11/ install - - gem install coveralls-lcov - - pip install --user cpp-coveralls - after_success: - - make clean - - CXXFLAGS="--coverage -g -O0" CPPFLAGS="-DNDEBUG" make json_unit - - test/json_unit "*" - - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' - - lcov --directory src --directory test/src --capture --output-file coverage.info --rc lcov_branch_coverage=1 --no-external - - lcov --remove coverage.info 'test/src/*' --output-file coverage.info --rc lcov_branch_coverage=1 - - lcov --list coverage.info --rc lcov_branch_coverage=1 - - coveralls-lcov --repo-token F9bs4Nop10JRgqPQXRcifyQKYhb3FczkS coverage.info - env: - - COMPILER=g++-4.9 - - SPECIAL=coveralls - - # Coverity (only for branch coverity_scan) - - - os: linux - compiler: clang - before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt - addons: - coverity_scan: - project: - name: "nlohmann/json" - description: "Build submitted via Travis CI" - notification_email: niels.lohmann@gmail.com - build_command_prepend: "make clean" - build_command: "make" - branch_pattern: coverity_scan - env: - - LLVM_VERSION=3.6.0 - - SPECIAL=coverity - - # OSX / Clang - - - os: osx - osx_image: xcode6.4 - - - os: osx - osx_image: xcode7.3 - - - os: osx - osx_image: xcode8 - - - os: osx - osx_image: xcode8.1 - - - os: osx - osx_image: xcode8.2 - - - os: osx - osx_image: xcode8.3 - - - os: osx - osx_image: xcode9 - - # Linux / GCC - - - os: linux - compiler: gcc - env: COMPILER=g++-4.9 - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-4.9 - - - os: linux - compiler: gcc - env: COMPILER=g++-5 - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-5 - - - os: linux - compiler: gcc - env: COMPILER=g++-6 - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-6 - - - os: linux - compiler: gcc - env: COMPILER=g++-7 - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-7 - - - os: linux - compiler: gcc - env: - - COMPILER=g++-7 - - CXXFLAGS=-std=c++17 - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: g++-7 - - # Linux / Clang - - - os: linux - env: LLVM_VERSION=3.6.0 - compiler: clang - - - os: linux - env: LLVM_VERSION=3.6.1 - compiler: clang - - - os: linux - env: LLVM_VERSION=3.6.2 - compiler: clang - -# - os: linux -# env: LLVM_VERSION=3.7.0 -# compiler: clang - -# - os: linux -# env: LLVM_VERSION=3.7.1 -# compiler: clang - - - os: linux - env: LLVM_VERSION=3.8.0 - compiler: clang - - - os: linux - env: LLVM_VERSION=3.8.1 - compiler: clang - -# - os: linux -# addons: -# apt: -# sources: llvm-toolchain-trusty-3.9 -# packages: clang-3.9 -# env: COMPILER=clang++-3.9 -# -# - os: linux -# addons: -# apt: -# sources: llvm-toolchain-trusty-4.0 -# packages: clang-4.0 -# env: COMPILER=clang++-4.0 -# -# - os: linux -# addons: -# apt: -# sources: llvm-toolchain-trusty -# packages: clang-5.0 -# env: COMPILER=clang++-5.0 - -##################### -# installation step # -##################### - -# set directories to cache -cache: - directories: - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.2 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.1 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.0 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.0 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.1 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.0 - - ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1 - - -install: - # create deps dir if not existing - - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" - - mkdir -p ${DEPS_DIR} - - # make sure CXX is correctly set - - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi - - # get CMake (only for systems with brew - macOS) - - | - if [[ !(-x $(which cmake)) && (-x $(which brew)) ]]; then - brew update - brew install cmake - cmake --version - fi - - # install LLVM/clang when LLVM_VERSION is set - - | - if [[ "${LLVM_VERSION}" != "" ]]; then - LLVM_DIR=${DEPS_DIR}/llvm-${LLVM_VERSION} - if [[ -z "$(ls -A ${LLVM_DIR})" ]]; then - travis_retry wget --quiet https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz - tar xfz cmake-3.6.1.tar.gz - (cd cmake-3.6.1 && ./configure --prefix=${LLVM_DIR}/cmake && make install) - export PATH="${LLVM_DIR}/cmake/bin:${PATH}" - LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" - LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz" - LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz" - CLANG_URL="http://llvm.org/releases/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz" - mkdir -p ${LLVM_DIR} ${LLVM_DIR}/build ${LLVM_DIR}/projects/libcxx ${LLVM_DIR}/projects/libcxxabi ${LLVM_DIR}/clang - travis_retry wget --quiet -O - ${LLVM_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR} - travis_retry wget --quiet -O - ${LIBCXX_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxx - travis_retry wget --quiet -O - ${LIBCXXABI_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxxabi - travis_retry wget --quiet -O - ${CLANG_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/clang - (cd ${LLVM_DIR}/build && cmake .. -DCMAKE_INSTALL_PREFIX=${LLVM_DIR}/install -DCMAKE_CXX_COMPILER=clang++) - (cd ${LLVM_DIR}/build/projects/libcxx && make install -j2) - (cd ${LLVM_DIR}/build/projects/libcxxabi && make install -j2) - fi - export CXXFLAGS="-nostdinc++ -isystem ${LLVM_DIR}/install/include/c++/v1" - export LDFLAGS="-L ${LLVM_DIR}/install/lib -l c++ -l c++abi" - export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_DIR}/install/lib" - export PATH="${LLVM_DIR}/clang/bin:${PATH}" - fi + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8'] + packages: ['g++-6', 'clang-3.8'] ################ # build script # ################ script: + # make sure CXX is correctly set + - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi + # show OS/compiler version - uname -a - $CXX --version @@ -324,11 +53,3 @@ script: - cmake .. && cmake --build . --config Release -- -j4 - ctest -C Release -V - cd .. - - # check if homebrew works (only checks develop branch) - - if [ `which brew` ]; then - brew update ; - brew tap nlohmann/json ; - brew install nlohmann_json --HEAD ; - brew test nlohmann_json ; - fi From eb6de822bb0beb4f2d208bea7995ff72bb47c395 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:12:04 +0200 Subject: [PATCH 11/36] :construction_worker: clang-3.7 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 775235c3..822cd120 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,8 @@ matrix: env: COMPILER=clang-3.8 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8'] - packages: ['g++-6', 'clang-3.8'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.7'] + packages: ['g++-6', 'clang-3.7'] ################ # build script # From e3335626338aea6d5cb2e6ef9514ac4598e40e48 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:15:16 +0200 Subject: [PATCH 12/36] :construction_worker: different source --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 822cd120..b7125e16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: env: COMPILER=clang-3.8 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.7'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] packages: ['g++-6', 'clang-3.7'] ################ From e7a7e4f81f736baaf52c6ba95993677b607ca272 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:18:45 +0200 Subject: [PATCH 13/36] :construction_worker: fixed compiler --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b7125e16..ede6406d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,8 +29,8 @@ matrix: include: - os: linux - compiler: gcc - env: COMPILER=clang-3.8 + compiler: clang + env: COMPILER=clang-3.7 addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] From 5aceb0e029fd4e3862dacc7b6c77a1d380d61d47 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:23:55 +0200 Subject: [PATCH 14/36] :construction_worker: clang-3.6 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ede6406d..fe32c646 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang-3.7 + env: COMPILER=clang-3.6 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] - packages: ['g++-6', 'clang-3.7'] + sources: ['ubuntu-toolchain-r-test''] + packages: ['g++-6', 'clang-3.6'] ################ # build script # From 8963aae57d83f51d6f5d56eddadf05476b12ef71 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:24:36 +0200 Subject: [PATCH 15/36] :construction_worker: clang-3.6 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fe32c646..f96eecb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: env: COMPILER=clang-3.6 addons: apt: - sources: ['ubuntu-toolchain-r-test''] + sources: ['ubuntu-toolchain-r-test'] packages: ['g++-6', 'clang-3.6'] ################ From 94dfecd4873d35bc5e590a8a34394cca6c71519e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:31:43 +0200 Subject: [PATCH 16/36] :construction_worker: removed g++ --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f96eecb9..edf4970b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,7 @@ matrix: env: COMPILER=clang-3.6 addons: apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'clang-3.6'] + packages: ['clang-3.6'] ################ # build script # From c20dd7522f552dd0f28e916f1b73302d4c8af370 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:40:09 +0200 Subject: [PATCH 17/36] :construction_worker: another try --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index edf4970b..6165441d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,8 @@ matrix: env: COMPILER=clang-3.6 addons: apt: - packages: ['clang-3.6'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] + packages: ['g++-6', 'clang-3.6'] ################ # build script # From 3283352db3f7ceedc849bd74a27b077c2dd902df Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:45:33 +0200 Subject: [PATCH 18/36] :construction_worker: using clang++ --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6165441d..a7d42d67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang-3.6 + env: COMPILER=clang++-3.6 addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] From c06b5c5c10136d95f8964414d0a0a62354deebc8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:50:36 +0200 Subject: [PATCH 19/36] :construction_worker: clang-3.5 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a7d42d67..41bc2215 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.6 + env: COMPILER=clang++-3.5 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] - packages: ['g++-6', 'clang-3.6'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] + packages: ['g++-6', 'clang-3.5'] ################ # build script # From f256587c4f2e07679f6c2ddc3d05f8b8a1a5d1bc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:56:09 +0200 Subject: [PATCH 20/36] :construction_worker: clang-3.4 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 41bc2215..94360961 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.5 + env: COMPILER=clang++-3.4 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] - packages: ['g++-6', 'clang-3.5'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.4'] + packages: ['g++-6', 'clang-3.4'] ################ # build script # From 82cd8c8d02d4523c4f6ccd70d5bf7ce09b40858f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 19:59:00 +0200 Subject: [PATCH 21/36] :construction_worker: another try --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 94360961..26fc7492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: env: COMPILER=clang++-3.4 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.4'] + sources: ['ubuntu-toolchain-r-test'] packages: ['g++-6', 'clang-3.4'] ################ From 6b20f6d1efce2b7be3a05e9b583b432da846f420 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:04:36 +0200 Subject: [PATCH 22/36] :construction_worker: clang-3.8 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 26fc7492..bea857da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.4 + env: COMPILER=clang++-3.8 addons: apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'clang-3.4'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.8'] + packages: ['g++-6', 'clang-3.8'] ################ # build script # From e7f2d2646a898a19c70e3d2e647e1e91b2608999 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:06:47 +0200 Subject: [PATCH 23/36] :construction_worker: removed gcc --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bea857da..66211c9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,8 +33,7 @@ matrix: env: COMPILER=clang++-3.8 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.8'] - packages: ['g++-6', 'clang-3.8'] + packages: ['clang-3.8'] ################ # build script # From 195d773bc5a33b1a908eb3f19f13fd0d00402b7c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:09:39 +0200 Subject: [PATCH 24/36] :construction_worker: added gcc --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 66211c9f..3e544b66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: env: COMPILER=clang++-3.8 addons: apt: - packages: ['clang-3.8'] + packages: ['g++-6', 'clang-3.8'] ################ # build script # From 8de710bbe7cc0a882c507017791081a2913bea06 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:12:27 +0200 Subject: [PATCH 25/36] :construction_worker: added source for gcc --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3e544b66..7acc7cb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,7 @@ matrix: env: COMPILER=clang++-3.8 addons: apt: + sources: ['ubuntu-toolchain-r-test'] packages: ['g++-6', 'clang-3.8'] ################ From 6dc89e47fce58cedd61f7d8d1b0537cf6fb83c69 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:16:35 +0200 Subject: [PATCH 26/36] :construction_worker: clang-3.9 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7acc7cb4..ae923a0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.8 + env: COMPILER=clang++-3.9 addons: apt: sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'clang-3.8'] + packages: ['g++-6', 'clang-3.9'] ################ # build script # From e0f8eb171079082dc993756b440c06350323cfd8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:21:41 +0200 Subject: [PATCH 27/36] :construction_worker: clang-4.0 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae923a0f..2a737749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.9 + env: COMPILER=clang++-4.0 addons: apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'clang-3.9'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] + packages: ['g++-6', 'clang-4.0'] ################ # build script # From f49356e7031e32c3dce3342c4bf07a2312083113 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:26:49 +0200 Subject: [PATCH 28/36] :construction_worker: clang-3.4 --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a737749..aee42cd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,19 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-4.0 + env: COMPILER=clang++-3.4 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] - packages: ['g++-6', 'clang-4.0'] + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-6', 'clang-3.4'] + + - os: linux + compiler: clang + env: COMPILER=clang++-3.5 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] + packages: ['g++-6', 'clang-3.5'] ################ # build script # From 5eb9f5fd4f0bde6f6bc312545521fd02db9a9b5e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:31:59 +0200 Subject: [PATCH 29/36] :construction_worker: clang-3.4 --- .travis.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index aee42cd3..405a2587 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,19 +30,10 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-3.4 + env: COMPILER=clang++ addons: apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'clang-3.4'] - - - os: linux - compiler: clang - env: COMPILER=clang++-3.5 - addons: - apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] - packages: ['g++-6', 'clang-3.5'] + packages: ['clang-3.4'] ################ # build script # From cd34358e7c6bba263a30055a6f29d274c616173e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:37:23 +0200 Subject: [PATCH 30/36] :construction_worker: removing clang from source --- .travis.yml | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 225 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 405a2587..8619bdc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,12 +28,226 @@ env: matrix: include: + # Valgrind + - os: linux - compiler: clang - env: COMPILER=clang++ + compiler: gcc + env: + - COMPILER=g++-4.9 + - SPECIAL=valgrind addons: apt: - packages: ['clang-3.4'] + sources: ['ubuntu-toolchain-r-test'] + packages: [g++-4.9, valgrind] + after_success: + - make check TEST_PREFIX="valgrind --error-exitcode=1 --leak-check=full " TEST_PATTERN="" + + # cLang sanitizer + # note: sadly clang's libc++ has errors when running with sanitize, + # so we use clang with gcc's libstdc++ which doesn't give those error. + # that's why we need to install g++-6 to get the lastest version + - os: linux + env: + - LLVM_VERSION=3.8.1 + - SPECIAL=sanitizer + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-6 + compiler: clang + before_script: + - make clang_sanitize + + # cppcheck + + - os: linux + compiler: gcc + env: + - COMPILER=g++-4.9 + - SPECIAL=cppcheck + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: [g++-4.9, cppcheck] + after_success: + - make cppcheck + + # no exceptions + + - os: linux + compiler: gcc + env: + - COMPILER=g++-4.9 + - SPECIAL=no_exceptions + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: [g++-4.9, cppcheck] + after_success: + - make clean + - CPPFLAGS="-DJSON_NOEXCEPTION" make check TEST_PATTERN="-e \"*\"" + + # Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/) + + - os: linux + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-4.9', 'ruby'] + before_script: + - wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz + - tar xf lcov_1.11.orig.tar.gz + - sudo make -C lcov-1.11/ install + - gem install coveralls-lcov + - pip install --user cpp-coveralls + after_success: + - make clean + - CXXFLAGS="--coverage -g -O0" CPPFLAGS="-DNDEBUG" make json_unit + - test/json_unit "*" + - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' + - lcov --directory src --directory test/src --capture --output-file coverage.info --rc lcov_branch_coverage=1 --no-external + - lcov --remove coverage.info 'test/src/*' --output-file coverage.info --rc lcov_branch_coverage=1 + - lcov --list coverage.info --rc lcov_branch_coverage=1 + - coveralls-lcov --repo-token F9bs4Nop10JRgqPQXRcifyQKYhb3FczkS coverage.info + env: + - COMPILER=g++-4.9 + - SPECIAL=coveralls + + # Coverity (only for branch coverity_scan) + + - os: linux + compiler: clang + before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt + addons: + coverity_scan: + project: + name: "nlohmann/json" + description: "Build submitted via Travis CI" + notification_email: niels.lohmann@gmail.com + build_command_prepend: "make clean" + build_command: "make" + branch_pattern: coverity_scan + env: + - LLVM_VERSION=3.6.0 + - SPECIAL=coverity + + # OSX / Clang + + - os: osx + osx_image: xcode6.4 + + - os: osx + osx_image: xcode7.3 + + - os: osx + osx_image: xcode8 + + - os: osx + osx_image: xcode8.1 + + - os: osx + osx_image: xcode8.2 + + - os: osx + osx_image: xcode8.3 + + - os: osx + osx_image: xcode9 + + # Linux / GCC + + - os: linux + compiler: gcc + env: COMPILER=g++-4.9 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-4.9 + + - os: linux + compiler: gcc + env: COMPILER=g++-5 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-5 + + - os: linux + compiler: gcc + env: COMPILER=g++-6 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-6 + + - os: linux + compiler: gcc + env: COMPILER=g++-7 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-7 + + - os: linux + compiler: gcc + env: + - COMPILER=g++-7 + - CXXFLAGS=-std=c++17 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-7 + + # Linux / Clang + + - os: linux + compiler: clang + env: COMPILER=clang++-3.5 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] + packages: ['g++-6', 'clang-3.5'] + + - os: linux + compiler: clang + env: COMPILER=clang++-3.6 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] + packages: ['g++-6', 'clang-3.6'] + + - os: linux + compiler: clang + env: COMPILER=clang++-3.7 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] + packages: ['g++-6', 'clang-3.7'] + + - os: linux + compiler: clang + env: COMPILER=clang++-3.8 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-6', 'clang-3.8'] + + - os: linux + compiler: clang + env: COMPILER=clang++-3.9 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-6', 'clang-3.9'] + + - os: linux + compiler: clang + env: COMPILER=clang++-4.0 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] + packages: ['g++-6', 'clang-4.0'] ################ # build script # @@ -52,3 +266,11 @@ script: - cmake .. && cmake --build . --config Release -- -j4 - ctest -C Release -V - cd .. + + # check if homebrew works (only checks develop branch) + - if [ `which brew` ]; then + brew update ; + brew tap nlohmann/json ; + brew install nlohmann_json --HEAD ; + brew test nlohmann_json ; + fi From 76b195d7d12650c48ac673871e8b6f5a1665c1ec Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 20:54:59 +0200 Subject: [PATCH 31/36] :construction_worker: fix for coverity + clang-5.0 --- .travis.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8619bdc1..e36e9cd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -120,6 +120,9 @@ matrix: compiler: clang before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] + packages: ['g++-6', 'clang-3.6'] coverity_scan: project: name: "nlohmann/json" @@ -129,8 +132,8 @@ matrix: build_command: "make" branch_pattern: coverity_scan env: - - LLVM_VERSION=3.6.0 - SPECIAL=coverity + - COMPILER=clang++-3.6 # OSX / Clang @@ -249,6 +252,14 @@ matrix: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] packages: ['g++-6', 'clang-4.0'] + - os: linux + compiler: clang + env: COMPILER=clang++-5.0 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty'] + packages: ['g++-6', 'clang-5.0'] + ################ # build script # ################ From bade3b3e6c33581d119a194f3ca80b4eb42f0d2a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 21:17:40 +0200 Subject: [PATCH 32/36] :construction_worker: cleanup --- .travis.yml | 8 +++++--- README.md | 15 +++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index e36e9cd1..922bb7df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -254,11 +254,13 @@ matrix: - os: linux compiler: clang - env: COMPILER=clang++-5.0 + env: + - COMPILER=clang++-4.0 + - CXXFLAGS=-std=c++17 addons: apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty'] - packages: ['g++-6', 'clang-5.0'] + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] + packages: ['g++-6', 'clang-4.0'] ################ # build script # diff --git a/README.md b/README.md index fcfe58ca..92d1956a 100644 --- a/README.md +++ b/README.md @@ -712,7 +712,7 @@ json j_from_msgpack = json::from_msgpack(v_msgpack); Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work: - GCC 4.9 - 7.1 (and possibly later) -- Clang 3.4 - 3.9 (and possibly later) +- Clang 3.4 - 4.0 (and possibly later) - Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later) - Microsoft Visual C++ 2017 / Build Tools 15.1.548.43366 (and possibly later) @@ -741,13 +741,12 @@ The following compilers are currently used in continuous integration at [Travis] | GCC 5.4.1 | Ubuntu 14.04.5 LTS | g++-5 (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904 | | GCC 6.3.0 | Ubuntu 14.04.5 LTS | g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~14.04) 6.3.0 20170519 | | GCC 7.1.0 | Ubuntu 14.04.5 LTS | g++-7 (Ubuntu 7.1.0-5ubuntu2~14.04) 7.1.0 -| Clang 3.6.0 | Ubuntu 14.04.5 LTS | clang version 3.6.0 (tags/RELEASE_360/final) | -| Clang 3.6.1 | Ubuntu 14.04.5 LTS | clang version 3.6.1 (tags/RELEASE_361/final) | -| Clang 3.6.2 | Ubuntu 14.04.5 LTS | clang version 3.6.2 (tags/RELEASE_362/final) | -| Clang 3.7.0 | Ubuntu 14.04.5 LTS | clang version 3.7.0 (tags/RELEASE_370/final) | -| Clang 3.7.1 | Ubuntu 14.04.5 LTS | clang version 3.7.1 (tags/RELEASE_371/final) | -| Clang 3.8.0 | Ubuntu 14.04.5 LTS | clang version 3.8.0 (tags/RELEASE_380/final) | -| Clang 3.8.1 | Ubuntu 14.04.5 LTS | clang version 3.8.1 (tags/RELEASE_381/final) | +| Clang 3.5.0 | Ubuntu 14.04.5 LTS | clang version 3.5.0-4ubuntu2~trusty2 (tags/RELEASE_350/final) | +| Clang 3.6.2 | Ubuntu 14.04.5 LTS | clang version 3.6.2-svn240577-1~exp1 (branches/release_36) | +| Clang 3.7.1 | Ubuntu 14.04.5 LTS | clang version 3.7.1-svn253571-1~exp1 (branches/release_37) | +| Clang 3.8.0 | Ubuntu 14.04.5 LTS | clang version 3.8.0-2ubuntu3~trusty5 (tags/RELEASE_380/final) | +| Clang 3.9.1 | Ubuntu 14.04.5 LTS | clang version 3.9.1-4ubuntu3~14.04.2 (tags/RELEASE_391/rc2) | +| Clang 4.0.1 | Ubuntu 14.04.5 LTS | clang version 4.0.1-svn305264-1~exp1 (branches/release_40) | | Clang Xcode 6.4 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) | | Clang Xcode 7.3 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.3.0 (clang-703.0.29) | | Clang Xcode 8.0 | Darwin Kernel Version 15.6.0 | Apple LLVM version 8.0.0 (clang-800.0.38) | From 6151b056eb2204cb79576e546619a8ea11689f67 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 23:40:30 +0200 Subject: [PATCH 33/36] :hammer: cleanup --- src/json.hpp | 253 +++++++++------------------------------------------ 1 file changed, 42 insertions(+), 211 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index fdade71f..a704d864 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -463,13 +463,9 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept }; // discarded values are not comparable - if (lhs == value_t::discarded or rhs == value_t::discarded) - { - return false; - } + return lhs != value_t::discarded and rhs != value_t::discarded and + order[static_cast(lhs)] < order[static_cast(rhs)]; - return order[static_cast(lhs)] < - order[static_cast(rhs)]; } @@ -1007,10 +1003,9 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) val = static_cast(*j.template get_ptr()); break; } + default: - { JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); - } } } @@ -1198,10 +1193,9 @@ void from_json(const BasicJsonType& j, ArithmeticType& val) val = static_cast(*j.template get_ptr()); break; } + default: - { JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()))); - } } } @@ -1629,11 +1623,8 @@ class lexer return "end of input"; case token_type::literal_or_value: return "'[', '{', or a literal"; - default: - { - // catch non-enum values + default: // catch non-enum values return "unknown token"; // LCOV_EXCL_LINE - } } } @@ -2339,9 +2330,7 @@ scan_number_zero: } default: - { goto scan_number_done; - } } scan_number_any1: @@ -2377,9 +2366,7 @@ scan_number_any1: } default: - { goto scan_number_done; - } } scan_number_decimal1: @@ -2436,9 +2423,7 @@ scan_number_decimal2: } default: - { goto scan_number_done; - } } scan_number_exponent: @@ -2522,9 +2507,7 @@ scan_number_any2: } default: - { goto scan_number_done; - } } scan_number_done: @@ -2911,12 +2894,8 @@ class parser return false; } - if (strict and get_token() != token_type::end_of_input) - { - return false; - } - - return true; + // strict => last token must be EOF + return not strict or (get_token() == token_type::end_of_input); } private: @@ -3156,10 +3135,7 @@ class parser JSON_THROW(out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'")); } - else - { - expect(token_type::uninitialized); - } + expect(token_type::uninitialized); } break; } @@ -3297,15 +3273,10 @@ class parser case token_type::value_integer: case token_type::value_string: case token_type::value_unsigned: - { return true; - } - default: - { - // the last token was unexpected + default: // the last token was unexpected return false; - } } } @@ -3740,9 +3711,7 @@ class iter_impl : public std::iteratorm_type) { case value_t::object: - { return (m_it.object_iterator == other.m_it.object_iterator); - } case value_t::array: - { return (m_it.array_iterator == other.m_it.array_iterator); - } default: - { return (m_it.primitive_iterator == other.m_it.primitive_iterator); - } } } @@ -3935,19 +3898,13 @@ class iter_impl : public std::iteratorm_type) { case value_t::object: - { JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators")); - } case value_t::array: - { return (m_it.array_iterator < other.m_it.array_iterator); - } default: - { return (m_it.primitive_iterator < other.m_it.primitive_iterator); - } } } @@ -3989,9 +3946,7 @@ class iter_impl : public std::iteratorm_type) { case value_t::object: - { JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); - } case value_t::array: { @@ -4062,19 +4017,13 @@ class iter_impl : public std::iteratorm_type) { case value_t::object: - { JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators")); - } case value_t::array: - { return m_it.array_iterator - other.m_it.array_iterator; - } default: - { return m_it.primitive_iterator - other.m_it.primitive_iterator; - } } } @@ -4089,19 +4038,13 @@ class iter_impl : public std::iteratorm_type) { case value_t::object: - { JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators")); - } case value_t::array: - { return *std::next(m_it.array_iterator, n); - } case value_t::null: - { JSON_THROW(invalid_iterator::create(214, "cannot get value")); - } default: { @@ -4193,21 +4136,15 @@ template class iteration_proxy { // use integer array index as key case value_t::array: - { return std::to_string(array_index); - } // use key from the object case value_t::object: - { return anchor.key(); - } // use an empty key for all primitive types default: - { return ""; - } } } @@ -4486,9 +4423,7 @@ class binary_reader { // EOF case std::char_traits::eof(): - { JSON_THROW(parse_error::create(110, chars_read, "unexpected end of input")); - } // Integer 0x00..0x17 (0..23) case 0x00: @@ -4515,29 +4450,19 @@ class binary_reader case 0x15: case 0x16: case 0x17: - { return static_cast(current); - } case 0x18: // Unsigned integer (one-byte uint8_t follows) - { return get_number(); - } case 0x19: // Unsigned integer (two-byte uint16_t follows) - { return get_number(); - } case 0x1a: // Unsigned integer (four-byte uint32_t follows) - { return get_number(); - } case 0x1b: // Unsigned integer (eight-byte uint64_t follows) - { return get_number(); - } // Negative integer -1-0x00..-1-0x17 (-1..-24) case 0x20: @@ -4564,9 +4489,7 @@ class binary_reader case 0x35: case 0x36: case 0x37: - { return static_cast(0x20 - 1 - current); - } case 0x38: // Negative integer (one-byte uint8_t follows) { @@ -4896,9 +4819,7 @@ class binary_reader { // EOF case std::char_traits::eof(): - { JSON_THROW(parse_error::create(110, chars_read, "unexpected end of input")); - } // positive fixint case 0x00: @@ -5029,9 +4950,7 @@ class binary_reader case 0x7d: case 0x7e: case 0x7f: - { return static_cast(current); - } // fixmap case 0x80: @@ -5122,81 +5041,51 @@ class binary_reader case 0xbd: case 0xbe: case 0xbf: - { return get_msgpack_string(); - } case 0xc0: // nil - { return value_t::null; - } case 0xc2: // false - { return false; - } case 0xc3: // true - { return true; - } case 0xca: // float 32 - { return get_number(); - } case 0xcb: // float 64 - { return get_number(); - } case 0xcc: // uint 8 - { return get_number(); - } case 0xcd: // uint 16 - { return get_number(); - } case 0xce: // uint 32 - { return get_number(); - } case 0xcf: // uint 64 - { return get_number(); - } case 0xd0: // int 8 - { return get_number(); - } case 0xd1: // int 16 - { return get_number(); - } case 0xd2: // int 32 - { return get_number(); - } case 0xd3: // int 64 - { return get_number(); - } case 0xd9: // str 8 case 0xda: // str 16 case 0xdb: // str 32 - { return get_msgpack_string(); - } case 0xdc: // array 16 { @@ -5279,9 +5168,7 @@ class binary_reader case 0xfd: case 0xfe: case 0xff: - { return static_cast(current); - } default: // anything else { @@ -5718,9 +5605,8 @@ class binary_writer break; } - case value_t::number_float: + case value_t::number_float: // Double-Precision Float { - // Double-Precision Float oa->write_character(static_cast(0xfb)); write_number(j.m_value.number_float); break; @@ -5844,9 +5730,7 @@ class binary_writer } default: - { break; - } } } @@ -5857,16 +5741,14 @@ class binary_writer { switch (j.type()) { - case value_t::null: + case value_t::null: // nil { - // nil oa->write_character(static_cast(0xc0)); break; } - case value_t::boolean: + case value_t::boolean: // true and false { - // true and false oa->write_character(j.m_value.boolean ? static_cast(0xc3) : static_cast(0xc2)); @@ -5983,9 +5865,8 @@ class binary_writer break; } - case value_t::number_float: + case value_t::number_float: // float 64 { - // float 64 oa->write_character(static_cast(0xcb)); write_number(j.m_value.number_float); break; @@ -6088,9 +5969,7 @@ class binary_writer } default: - { break; - } } } @@ -6481,7 +6360,7 @@ class serializer return res; } - static void escape_codepoint(int codepoint, string_t& result, size_t& pos) + static void escape_codepoint(int codepoint, string_t& result, std::size_t& pos) { // expecting a proper codepoint assert(0x00 <= codepoint and codepoint <= 0x10FFFF); @@ -6563,56 +6442,49 @@ class serializer { switch (s[i]) { - // quotation mark (0x22) - case '"': + case '"': // quotation mark (0x22) { result[pos + 1] = '"'; pos += 2; break; } - // reverse solidus (0x5c) - case '\\': + case '\\': // reverse solidus (0x5c) { // nothing to change pos += 2; break; } - // backspace (0x08) - case '\b': + case '\b': // backspace (0x08) { result[pos + 1] = 'b'; pos += 2; break; } - // formfeed (0x0c) - case '\f': + case '\f': // formfeed (0x0c) { result[pos + 1] = 'f'; pos += 2; break; } - // newline (0x0a) - case '\n': + case '\n': // newline (0x0a) { result[pos + 1] = 'n'; pos += 2; break; } - // carriage return (0x0d) - case '\r': + case '\r': // carriage return (0x0d) { result[pos + 1] = 'r'; pos += 2; break; } - // horizontal tab (0x09) - case '\t': + case '\t': // horizontal tab (0x09) { result[pos + 1] = 't'; pos += 2; @@ -6780,7 +6652,7 @@ class serializer // negative value indicates an error assert(len > 0); // check if buffer was large enough - assert(static_cast(len) < number_buffer.size()); + assert(static_cast(len) < number_buffer.size()); // erase thousands separator if (thousands_sep != '\0') @@ -6805,7 +6677,7 @@ class serializer } } - o->write_characters(number_buffer.data(), static_cast(len)); + o->write_characters(number_buffer.data(), static_cast(len)); // determine if need to append ".0" const bool value_is_int_like = @@ -8710,9 +8582,7 @@ class basic_json } default: - { break; - } } switch (m_type) @@ -8762,10 +8632,8 @@ class basic_json } default: - { JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()))); - } } assert_invariant(); @@ -8851,9 +8719,7 @@ class basic_json } default: - { break; - } } assert_invariant(); @@ -10648,9 +10514,7 @@ class basic_json } default: - { JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); - } } return result; @@ -10758,9 +10622,7 @@ class basic_json } default: - { JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()))); - } } return result; @@ -11529,9 +11391,7 @@ class basic_json } default: - { break; - } } } @@ -12238,41 +12098,31 @@ class basic_json switch (lhs_type) { case value_t::array: - { return (*lhs.m_value.array == *rhs.m_value.array); - } + case value_t::object: - { return (*lhs.m_value.object == *rhs.m_value.object); - } + case value_t::null: - { return true; - } + case value_t::string: - { return (*lhs.m_value.string == *rhs.m_value.string); - } + case value_t::boolean: - { return (lhs.m_value.boolean == rhs.m_value.boolean); - } + case value_t::number_integer: - { return (lhs.m_value.number_integer == rhs.m_value.number_integer); - } + case value_t::number_unsigned: - { return (lhs.m_value.number_unsigned == rhs.m_value.number_unsigned); - } + case value_t::number_float: - { return (lhs.m_value.number_float == rhs.m_value.number_float); - } + default: - { return false; - } } } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) @@ -12402,41 +12252,31 @@ class basic_json switch (lhs_type) { case value_t::array: - { return (*lhs.m_value.array) < (*rhs.m_value.array); - } + case value_t::object: - { return *lhs.m_value.object < *rhs.m_value.object; - } + case value_t::null: - { return false; - } + case value_t::string: - { return *lhs.m_value.string < *rhs.m_value.string; - } + case value_t::boolean: - { return lhs.m_value.boolean < rhs.m_value.boolean; - } + case value_t::number_integer: - { return lhs.m_value.number_integer < rhs.m_value.number_integer; - } + case value_t::number_unsigned: - { return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned; - } + case value_t::number_float: - { return lhs.m_value.number_float < rhs.m_value.number_float; - } + default: - { return false; - } } } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) @@ -14105,9 +13945,7 @@ json_pointer::get_and_create(NLOHMANN_BASIC_JSON_TPL& j) const single value; that is, with an empty list of reference tokens. */ default: - { JSON_THROW(detail::type_error::create(313, "invalid value to unflatten")); - } } } @@ -14179,9 +14017,7 @@ json_pointer::get_unchecked(NLOHMANN_BASIC_JSON_TPL* ptr) const } default: - { JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } } } @@ -14235,9 +14071,7 @@ json_pointer::get_checked(NLOHMANN_BASIC_JSON_TPL* ptr) const } default: - { JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } } } @@ -14292,9 +14126,7 @@ json_pointer::get_unchecked(const NLOHMANN_BASIC_JSON_TPL* ptr) const } default: - { JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } } } @@ -14348,9 +14180,7 @@ json_pointer::get_checked(const NLOHMANN_BASIC_JSON_TPL* ptr) const } default: - { JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'")); - } } } @@ -14491,9 +14321,10 @@ struct hash }; /// specialization for std::less +/// @note: do not remove the space after '<', +/// see https://github.com/nlohmann/json/pull/679 template<> -struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', - // see https://github.com/nlohmann/json/pull/679 +struct less< ::nlohmann::detail::value_t> { /*! @brief compare two value_t enum values From 569c00eb18269d8a53973cbe06f344bc7bdffc1d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 10 Aug 2017 23:41:12 +0200 Subject: [PATCH 34/36] :construction_worker: changed c++17 to c++1z --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 922bb7df..7969af18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -256,7 +256,7 @@ matrix: compiler: clang env: - COMPILER=clang++-4.0 - - CXXFLAGS=-std=c++17 + - CXXFLAGS=-std=c++1z addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] From 7d19aed56741534c8815d52c7030944f3509f219 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 13 Aug 2017 19:02:58 +0200 Subject: [PATCH 35/36] :hammer: cleanup --- src/json.hpp | 285 +++++++++++++++++++++------------------------------ 1 file changed, 117 insertions(+), 168 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index a704d864..0ac3e5ff 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -465,7 +465,6 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept // discarded values are not comparable return lhs != value_t::discarded and rhs != value_t::discarded and order[static_cast(lhs)] < order[static_cast(rhs)]; - } @@ -1075,11 +1074,11 @@ void from_json(const BasicJsonType& j, std::forward_list& l) { JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()))); } - - for (auto it = j.rbegin(), end = j.rend(); it != end; ++it) + std::transform(j.rbegin(), j.rend(), + std::front_inserter(l), [](const BasicJsonType & i) { - l.push_front(it->template get()); - } + return i.template get(); + }); } template @@ -1673,7 +1672,8 @@ class lexer assert(current == 'u'); int codepoint = 0; - for (int factor = 12; factor >= 0; factor -= 4) + const auto factors = { 12, 8, 4, 0 }; + for (const auto factor : factors) { get(); @@ -2520,11 +2520,12 @@ scan_number_done: add('\0'); --yylen; + char* endptr = nullptr; + errno = 0; + // try to parse integers first and fall back to floats if (number_type == token_type::value_unsigned) { - char* endptr = nullptr; - errno = 0; const auto x = std::strtoull(yytext.data(), &endptr, 10); // we checked the number format before @@ -2541,8 +2542,6 @@ scan_number_done: } else if (number_type == token_type::value_integer) { - char* endptr = nullptr; - errno = 0; const auto x = std::strtoll(yytext.data(), &endptr, 10); // we checked the number format before @@ -2560,7 +2559,11 @@ scan_number_done: // this code is reached if we parse a floating-point number or if an // integer conversion above failed - strtof(value_float, yytext.data(), nullptr); + strtof(value_float, yytext.data(), &endptr); + + // we checked the number format before + assert(endptr == yytext.data() + yylen); + return token_type::value_float; } @@ -2683,7 +2686,7 @@ scan_number_done: else { // add character as is - result.append(1, c); + result.push_back(c); } } @@ -2834,8 +2837,7 @@ class parser explicit parser(detail::input_adapter_t adapter, const parser_callback_t cb = nullptr, const bool allow_exceptions_ = true) - : callback(cb), m_lexer(adapter), - allow_exceptions(allow_exceptions_) + : callback(cb), m_lexer(adapter), allow_exceptions(allow_exceptions_) {} /*! @@ -4573,57 +4575,27 @@ class binary_reader case 0x96: case 0x97: { - BasicJsonType result = value_t::array; - const auto len = static_cast(current & 0x1f); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_cbor()); - } - return result; + return get_cbor_array(current & 0x1f); } case 0x98: // array (one-byte uint8_t for n follows) { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_cbor()); - } - return result; + return get_cbor_array(get_number()); } case 0x99: // array (two-byte uint16_t for n follow) { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_cbor()); - } - return result; + return get_cbor_array(get_number()); } case 0x9a: // array (four-byte uint32_t for n follow) { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_cbor()); - } - return result; + return get_cbor_array(get_number()); } case 0x9b: // array (eight-byte uint64_t for n follow) { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_cbor()); - } - return result; + return get_cbor_array(get_number()); } case 0x9f: // array (indefinite length) @@ -4662,67 +4634,27 @@ class binary_reader case 0xb6: case 0xb7: { - BasicJsonType result = value_t::object; - const auto len = static_cast(current & 0x1f); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_cbor_string(); - result[key] = parse_cbor(); - } - return result; + return get_cbor_object(current & 0x1f); } case 0xb8: // map (one-byte uint8_t for n follows) { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_cbor_string(); - result[key] = parse_cbor(); - } - return result; + return get_cbor_object(get_number()); } case 0xb9: // map (two-byte uint16_t for n follow) { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_cbor_string(); - result[key] = parse_cbor(); - } - return result; + return get_cbor_object(get_number()); } case 0xba: // map (four-byte uint32_t for n follow) { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_cbor_string(); - result[key] = parse_cbor(); - } - return result; + return get_cbor_object(get_number()); } case 0xbb: // map (eight-byte uint64_t for n follow) { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_cbor_string(); - result[key] = parse_cbor(); - } - return result; + return get_cbor_object(get_number()); } case 0xbf: // map (indefinite length) @@ -4970,15 +4902,7 @@ class binary_reader case 0x8e: case 0x8f: { - BasicJsonType result = value_t::object; - const auto len = static_cast(current & 0x0f); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_msgpack_string(); - result[key] = parse_msgpack(); - } - return result; + return get_msgpack_object(current & 0x0f); } // fixarray @@ -4999,13 +4923,7 @@ class binary_reader case 0x9e: case 0x9f: { - BasicJsonType result = value_t::array; - const auto len = static_cast(current & 0x0f); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_msgpack()); - } - return result; + return get_msgpack_array(current & 0x0f); } // fixstr @@ -5089,50 +5007,22 @@ class binary_reader case 0xdc: // array 16 { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_msgpack()); - } - return result; + return get_msgpack_array(get_number()); } case 0xdd: // array 32 { - BasicJsonType result = value_t::array; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - result.push_back(parse_msgpack()); - } - return result; + return get_msgpack_array(get_number()); } case 0xde: // map 16 { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_msgpack_string(); - result[key] = parse_msgpack(); - } - return result; + return get_msgpack_object(get_number()); } case 0xdf: // map 32 { - BasicJsonType result = value_t::object; - const auto len = static_cast(get_number()); - for (std::size_t i = 0; i < len; ++i) - { - get(); - auto key = get_msgpack_string(); - result[key] = parse_msgpack(); - } - return result; + return get_msgpack_object(get_number()); } // positive fixint @@ -5260,15 +5150,16 @@ class binary_reader @throw parse_error.110 if input has less than @a len bytes */ - std::string get_string(const std::size_t len) + template + std::string get_string(const NumberType len) { std::string result; - for (std::size_t i = 0; i < len; ++i) + std::generate_n(std::back_inserter(result), len, [this]() { get(); check_eof(); - result.append(1, static_cast(current)); - } + return current; + }); return result; } @@ -5316,32 +5207,27 @@ class binary_reader case 0x76: case 0x77: { - const auto len = static_cast(current & 0x1f); - return get_string(len); + return get_string(current & 0x1f); } case 0x78: // UTF-8 string (one-byte uint8_t for n follows) { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0x79: // UTF-8 string (two-byte uint16_t for n follow) { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0x7a: // UTF-8 string (four-byte uint32_t for n follow) { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0x7b: // UTF-8 string (eight-byte uint64_t for n follow) { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0x7f: // UTF-8 string (indefinite length) @@ -5350,7 +5236,7 @@ class binary_reader while (get() != 0xff) { check_eof(); - result.append(1, static_cast(current)); + result.push_back(static_cast(current)); } return result; } @@ -5364,6 +5250,33 @@ class binary_reader } } + template + BasicJsonType get_cbor_array(const NumberType len) + { + BasicJsonType result = value_t::array; + std::generate_n(std::back_inserter(*result.m_value.array), len, [this]() + { + return parse_cbor(); + }); + return result; + } + + template + BasicJsonType get_cbor_object(const NumberType len) + { + BasicJsonType result = value_t::object; + std::generate_n(std::inserter(*result.m_value.object, + result.m_value.object->end()), + len, [this]() + { + get(); + auto key = get_cbor_string(); + auto val = parse_cbor(); + return std::make_pair(std::move(key), std::move(val)); + }); + return result; + } + /*! @brief reads a MessagePack string @@ -5415,26 +5328,22 @@ class binary_reader case 0xbe: case 0xbf: { - const auto len = static_cast(current & 0x1f); - return get_string(len); + return get_string(current & 0x1f); } case 0xd9: // str 8 { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0xda: // str 16 { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } case 0xdb: // str 32 { - const auto len = static_cast(get_number()); - return get_string(len); + return get_string(get_number()); } default: @@ -5447,6 +5356,33 @@ class binary_reader } } + template + BasicJsonType get_msgpack_array(const NumberType len) + { + BasicJsonType result = value_t::array; + std::generate_n(std::back_inserter(*result.m_value.array), len, [this]() + { + return parse_msgpack(); + }); + return result; + } + + template + BasicJsonType get_msgpack_object(const NumberType len) + { + BasicJsonType result = value_t::object; + std::generate_n(std::inserter(*result.m_value.object, + result.m_value.object->end()), + len, [this]() + { + get(); + auto key = get_msgpack_string(); + auto val = parse_msgpack(); + return std::make_pair(std::move(key), std::move(val)); + }); + return result; + } + /*! @brief check if input ended @throw parse_error.110 if input ended @@ -6091,6 +6027,7 @@ class serializer // last element assert(i != val.m_value.object->cend()); + assert(std::next(i) == val.m_value.object->cend()); o->write_characters(indent_string.c_str(), new_indent); o->write_character('\"'); dump_escaped(i->first, ensure_ascii); @@ -6118,6 +6055,7 @@ class serializer // last element assert(i != val.m_value.object->cend()); + assert(std::next(i) == val.m_value.object->cend()); o->write_character('\"'); dump_escaped(i->first, ensure_ascii); o->write_characters("\":", 2); @@ -6338,7 +6276,7 @@ class serializer if (bytes == 3) { // codepoints that need 4 bytes (i.e., 3 additional - // bytes) in UTF-8 needs a surrogate pair when \u + // bytes) in UTF-8 need a surrogate pair when \u // escaping is used: from 4 bytes to \uxxxx\uxxxx // (12 bytes) res += (12 - bytes - 1); @@ -7244,6 +7182,9 @@ class basic_json friend class ::nlohmann::detail::iter_impl; template friend class ::nlohmann::detail::binary_writer; + template + friend class ::nlohmann::detail::binary_reader; + /// workaround type for MSVC using basic_json_t = NLOHMANN_BASIC_JSON_TPL; @@ -12858,6 +12799,10 @@ class basic_json @note The mapping is **complete** in the sense that any JSON value type can be converted to a CBOR value. + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. + @note The following CBOR types are not used in the conversion: - byte strings (0x40..0x5f) - UTF-8 strings terminated by "break" (0x7f) @@ -12885,7 +12830,7 @@ class basic_json @sa http://cbor.io @sa @ref from_cbor(const std::vector&, const size_t) for the analogous deserialization - @sa @ref to_msgpack(const basic_json& for the related MessagePack format + @sa @ref to_msgpack(const basic_json&) for the related MessagePack format @since version 2.0.9 */ @@ -12965,6 +12910,10 @@ class basic_json @note Any MessagePack output created @ref to_msgpack can be successfully parsed by @ref from_msgpack. + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. + @param[in] j JSON value to serialize @return MessagePack serialization as byte vector @@ -14324,7 +14273,7 @@ struct hash /// @note: do not remove the space after '<', /// see https://github.com/nlohmann/json/pull/679 template<> -struct less< ::nlohmann::detail::value_t> +struct less< ::nlohmann::detail::value_t> { /*! @brief compare two value_t enum values From 08805f7f14440411bade9a359e0b5491fc5e55d8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 13 Aug 2017 20:57:27 +0200 Subject: [PATCH 36/36] :hammer: cleanup --- src/json.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 0ac3e5ff..582322f4 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -29,7 +29,7 @@ SOFTWARE. #ifndef NLOHMANN_JSON_HPP #define NLOHMANN_JSON_HPP -#include // all_of, copy, fill, find, for_each, none_of, remove, reverse, transform +#include // all_of, copy, fill, find, for_each, generate_n, none_of, remove, reverse, transform #include // array #include // assert #include // and, not, or @@ -6605,13 +6605,10 @@ class serializer // convert decimal point to '.' if (decimal_point != '\0' and decimal_point != '.') { - for (auto& c : number_buffer) + const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); + if (dec_pos != number_buffer.end()) { - if (c == decimal_point) - { - c = '.'; - break; - } + *dec_pos = '.'; } }