diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index f16bc910d..018e7b668 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -161,8 +161,6 @@ jobs: compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', 'latest'] container: silkeh/clang:${{ matrix.compiler }} steps: - - name: Install unzip and git - run: apt-get update ; apt-get install -y unzip git - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 124b089d7..c8cda3908 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -18,7 +18,7 @@ concurrency: jobs: mingw: - runs-on: windows-2019 + runs-on: windows-2022 strategy: matrix: architecture: [x64, x86] @@ -40,24 +40,14 @@ jobs: msvc: strategy: matrix: - runs_on: [windows-2019, windows-2022] build_type: [Debug, Release] architecture: [Win32, x64] std_version: [default, latest] - runs-on: ${{ matrix.runs_on }} + runs-on: windows-2022 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Set generator - id: generator - run: | - if [ "${{ matrix.runs_on }}" = "windows-2019" ]; then - echo "generator=Visual Studio 16 2019" >> $GITHUB_ENV - else - echo "generator=Visual Studio 17 2022" >> $GITHUB_ENV - fi - shell: bash - name: Set extra CXX_FLAGS for latest std_version id: cxxflags run: | @@ -68,11 +58,11 @@ jobs: fi shell: bash - name: Run CMake (Release) - run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags" + run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags" if: matrix.build_type == 'Release' shell: pwsh - name: Run CMake (Debug) - run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags" + run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags" if: matrix.build_type == 'Debug' shell: pwsh - name: Build @@ -80,34 +70,34 @@ jobs: - name: Test run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure - clang: - runs-on: windows-2019 - strategy: - matrix: - version: [11, 12, 13, 14, 15] - - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Install Clang - run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM" - - name: Run CMake - run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On - - name: Build - run: cmake --build build --parallel 10 - - name: Test - run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure - - clang-cl-12: - runs-on: windows-2019 - strategy: - matrix: - architecture: [Win32, x64] - - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Run CMake - run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On - - name: Build - run: cmake --build build --config Debug --parallel 10 - - name: Test - run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure +# clang: +# runs-on: windows-2025 +# strategy: +# matrix: +# version: [11, 12, 13, 14, 15] +# +# steps: +# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 +# - name: Install Clang +# run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM" +# - name: Run CMake +# run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On +# - name: Build +# run: cmake --build build --parallel 10 +# - name: Test +# run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure +# +# clang-cl-12: +# runs-on: windows-2025 +# strategy: +# matrix: +# architecture: [Win32, x64] +# +# steps: +# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 +# - name: Run CMake +# run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On +# - name: Build +# run: cmake --build build --config Debug --parallel 10 +# - name: Test +# run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure diff --git a/cmake/clang_flags.cmake b/cmake/clang_flags.cmake index 7c1e9cc64..b3dfa3144 100644 --- a/cmake/clang_flags.cmake +++ b/cmake/clang_flags.cmake @@ -6,6 +6,7 @@ # -Wno-padded We do not care about padding warnings. # -Wno-covered-switch-default All switches list all cases and a default case. # -Wno-unsafe-buffer-usage Otherwise Doctest would not compile. +# -Wno-missing-noreturn We found no way to silence this warning otherwise, see PR #4871 set(CLANG_CXXFLAGS -Werror @@ -17,4 +18,5 @@ set(CLANG_CXXFLAGS -Wno-padded -Wno-covered-switch-default -Wno-unsafe-buffer-usage + -Wno-missing-noreturn ) diff --git a/cmake/download_test_data.cmake b/cmake/download_test_data.cmake index 14376f4ca..c5dd2bf70 100644 --- a/cmake/download_test_data.cmake +++ b/cmake/download_test_data.cmake @@ -1,21 +1,33 @@ set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data) set(JSON_TEST_DATA_VERSION 3.1.0) +include(ExternalProject) + # if variable is set, use test data from given directory rather than downloading them if(JSON_TestDataDirectory) message(STATUS "Using test data in ${JSON_TestDataDirectory}.") add_custom_target(download_test_data) file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n") else() - find_package(Git) + # create a header with the path to the downloaded test data + file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/test_files\"\n") + + # download test data from GitHub release + ExternalProject_Add(download_test_data_project + URL "${JSON_TEST_DATA_URL}/archive/refs/tags/v${JSON_TEST_DATA_VERSION}.zip" + SOURCE_DIR "${CMAKE_BINARY_DIR}/test_files" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD TRUE + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + EXCLUDE_FROM_ALL TRUE + ) + # target to download test data add_custom_target(download_test_data - COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1 - COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS download_test_data_project ) - # create a header with the path to the downloaded test data - file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n") endif() # determine the operating system (for debug and support purposes) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 4acfd21c9..7896548ea 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -402,7 +402,7 @@ template struct is_iterator_of_multibyte { using value_type = typename std::iterator_traits::value_type; - enum + enum // NOLINT(cppcoreguidelines-use-enum-class) { value = sizeof(value_type) > 1 }; diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 06dcb63e1..d7fb42b64 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -655,7 +655,7 @@ struct is_ordered_map template static one test( decltype(&C::capacity) ) ; template static two test(...); - enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg,cppcoreguidelines-use-enum-class) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8e7ac2017..1fd570576 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4198,7 +4198,7 @@ struct is_ordered_map template static one test( decltype(&C::capacity) ) ; template static two test(...); - enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg,cppcoreguidelines-use-enum-class) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) @@ -6895,7 +6895,7 @@ template struct is_iterator_of_multibyte { using value_type = typename std::iterator_traits::value_type; - enum + enum // NOLINT(cppcoreguidelines-use-enum-class) { value = sizeof(value_type) > 1 }; diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index 2ca0d1c4c..bea84856d 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1352,7 +1352,7 @@ TEST_CASE("value conversion") #ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION SECTION("get an enum") { - enum c_enum { value_1, value_2 }; + enum c_enum { value_1, value_2 }; // NOLINT(cppcoreguidelines-use-enum-class) enum class cpp_enum { value_1, value_2 }; CHECK(json(value_1).get() == value_1); @@ -1601,7 +1601,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(cards, {cards::karo, "karo"} }) -enum TaskState // NOLINT(cert-int09-c,readability-enum-initial-value) +enum TaskState // NOLINT(cert-int09-c,readability-enum-initial-value,cppcoreguidelines-use-enum-class) { TS_STOPPED, TS_RUNNING, diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index a3c372349..a7f8e4ccb 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp @@ -23,7 +23,7 @@ using nlohmann::json; namespace { -enum test {}; +enum test {}; // NOLINT(cppcoreguidelines-use-enum-class) struct pod {}; struct pod_bis {}; diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 47b00e856..629028843 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -177,7 +177,7 @@ TEST_CASE("regression tests 1") #ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION SECTION("pull request #71 - handle enum type") { - enum { t = 0, u = 102}; + enum { t = 0, u = 102}; // NOLINT(cppcoreguidelines-use-enum-class) json j = json::array(); j.push_back(t); diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 54b3fd597..3df444a34 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -363,7 +363,7 @@ struct for_3204_foo struct for_3204_bar { - enum constructed_from_t + enum constructed_from_t // NOLINT(cppcoreguidelines-use-enum-class) { constructed_from_none = 0, constructed_from_foo = 1,