From 08032158a3aad68f42a9faecd74ef3a8bb0afae4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 18:00:24 +0200 Subject: [PATCH] Fix -Wextra-semi-stmt at its actual source, not assert() clang_flags.cmake blamed the global -Wno-extra-semi-stmt on assert(), but assert() expands to an expression under glibc and libc++ and does not trigger this warning. unit-assert_macro.cpp overrides JSON_ASSERT with "{if (!(x)) ++assert_counter; }", a bare block followed by a semicolon at every JSON_ASSERT(...) call site in the library; that was the actual source of 151 of the 208 -Wextra-semi-stmt sites found in a Clang 22 -Weverything sweep of the test suite with the flag removed. Switched to the standard do/while(false) macro idiom, which does not expand to a statement-plus-semicolon, and corrected the comment to name the remaining source instead: vendored Doctest's CAPTURE(x) shim, which already ends in a semicolon. Verified with clang++ -Wextra-semi-stmt (plus the file's other CI ignores) that unit-assert_macro.cpp now compiles without any -Wextra-semi-stmt diagnostic. Signed-off-by: Niels Lohmann #5725 item 8 (step 1 of 2; step 2 covers the CAPTURE() call sites) --- cmake/clang_flags.cmake | 3 ++- tests/src/unit-assert_macro.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/clang_flags.cmake b/cmake/clang_flags.cmake index 0619545ec..5ff3db11e 100644 --- a/cmake/clang_flags.cmake +++ b/cmake/clang_flags.cmake @@ -2,7 +2,8 @@ # -Wno-c++98-compat The library targets C++11. # -Wno-c++98-compat-pedantic The library targets C++11. # -Wno-deprecated-declarations The library contains annotations for deprecated functions. -# -Wno-extra-semi-stmt The library uses assert which triggers this warning. +# -Wno-extra-semi-stmt Vendored Doctest's CAPTURE() macro expands to a +# statement followed by a semicolon at every call site. # -Wno-padded We do not care about padding warnings. # -Wno-covered-switch-default All switches list all cases and a default case. # -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in diff --git a/tests/src/unit-assert_macro.cpp b/tests/src/unit-assert_macro.cpp index adedfc934..ab15b8e5f 100644 --- a/tests/src/unit-assert_macro.cpp +++ b/tests/src/unit-assert_macro.cpp @@ -18,7 +18,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow") static int assert_counter; /// set failure variable to true instead of calling assert(x) -#define JSON_ASSERT(x) {if (!(x)) ++assert_counter; } +#define JSON_ASSERT(x) do { if (!(x)) { ++assert_counter; } } while (false) #include using nlohmann::json;