From 85e41d06d363921590a383ad375fc434ab6fbd0a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 1 Jul 2026 20:16:12 +0200 Subject: [PATCH] :green_heart: fix build Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 10 +++------- single_include/nlohmann/json.hpp | 10 +++------- tests/CMakeLists.txt | 16 +++++++++++++++- tests/fmt_formatter/project/main.cpp | 10 +++------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 6a34898d7..6b9258efd 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5408,11 +5408,11 @@ struct formatter // NOLINT(cert-dcl58-c ++it; } - // ['#'] - "alternate form", used here to request pretty-printing - bool pretty = false; + // ['#'] - "alternate form", used here to request pretty-printing with a + // default indent of 4 (overridden by an explicit width below, if given) if (it != end && *it == '#') { - pretty = true; + indent = 4; ++it; } @@ -5428,10 +5428,6 @@ struct formatter // NOLINT(cert-dcl58-c ++it; } } - else if (pretty) - { - indent = 4; - } // sign, the '0' flag, precision, locale-specific formatting ('L'), dynamic // width/precision ("{...}"), and type characters all have no meaning for diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 544d8ddd5..3d55cb622 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25934,11 +25934,11 @@ struct formatter // NOLINT(cert-dcl58-c ++it; } - // ['#'] - "alternate form", used here to request pretty-printing - bool pretty = false; + // ['#'] - "alternate form", used here to request pretty-printing with a + // default indent of 4 (overridden by an explicit width below, if given) if (it != end && *it == '#') { - pretty = true; + indent = 4; ++it; } @@ -25954,10 +25954,6 @@ struct formatter // NOLINT(cert-dcl58-c ++it; } } - else if (pretty) - { - indent = 4; - } // sign, the '0' flag, precision, locale-specific formatting ('L'), dynamic // width/precision ("{...}"), and type characters all have no meaning for diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 027881095..317ada91f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -195,4 +195,18 @@ add_subdirectory(cmake_add_subdirectory) add_subdirectory(cmake_fetch_content) add_subdirectory(cmake_fetch_content2) add_subdirectory(cmake_target_include_directories) -add_subdirectory(fmt_formatter) + +# fmt (fetched by tests/fmt_formatter) requires a genuinely modern, C++17-capable +# toolchain; skip it on legacy/niche toolchains where fmt itself is known not to build +set(JSON_FMT_FORMATTER_TEST_SUPPORTED ${compiler_supports_cpp_17}) +# fmt 12's 128-bit integer emulation does not build with 32-bit MinGW +if (MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(JSON_FMT_FORMATTER_TEST_SUPPORTED FALSE) +endif() +# the MSVC STL rejects Clang versions older than 19 as a host compiler +if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + set(JSON_FMT_FORMATTER_TEST_SUPPORTED FALSE) +endif() +if (JSON_FMT_FORMATTER_TEST_SUPPORTED) + add_subdirectory(fmt_formatter) +endif() diff --git a/tests/fmt_formatter/project/main.cpp b/tests/fmt_formatter/project/main.cpp index c0cecdc23..d50632249 100644 --- a/tests/fmt_formatter/project/main.cpp +++ b/tests/fmt_formatter/project/main.cpp @@ -35,11 +35,11 @@ struct fmt::formatter ++it; } - // ['#'] - "alternate form", used here to request pretty-printing - bool pretty = false; + // ['#'] - "alternate form", used here to request pretty-printing with a + // default indent of 4 (overridden by an explicit width below, if given) if (it != end && *it == '#') { - pretty = true; + indent = 4; ++it; } @@ -54,10 +54,6 @@ struct fmt::formatter ++it; } } - else if (pretty) - { - indent = 4; - } if (it != end && *it != '}') {