From 2a76599925bda95cf91a460a42f32bbb37e58d7b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 09:51:14 +0200 Subject: [PATCH] Fix ci_test_clang_libcxx_cxx* jobs silently building without warnings CMake only seeds CMAKE_CXX_FLAGS from the CXXFLAGS environment variable when the cache entry is unset, so the explicit -DCMAKE_CXX_FLAGS="-stdlib=libc++" argument made it ignore CXXFLAGS="${CLANG_CXXFLAGS}" entirely. The six ci_test_standards_clang (..., libcxx) jobs therefore compiled without -Weverything/-Werror while their libstdc++ siblings did use them. Pass -stdlib=libc++ through the same CXXFLAGS value instead of a separate -D argument, and give the target its own build directory (build_clang_libcxx_cxx${CXX_STANDARD}) so it no longer shares a CMake cache with the libstdc++ variant. Suppress the resulting -Wthread-safety-negative finding from libc++'s std::mutex annotations, which fires on doctest's reporters in this translation unit only. Part of #5715 Signed-off-by: Niels Lohmann --- cmake/ci.cmake | 10 +++++----- tests/src/unit.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index 84804ba9e..512adc9f7 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -128,16 +128,16 @@ foreach(CXX_STANDARD 11 14 17 20 23 26) COMMENT "Compile and test with Clang for C++${CXX_STANDARD}" ) + # pass -stdlib=libc++ through CXXFLAGS: an explicit -DCMAKE_CXX_FLAGS would make CMake ignore CXXFLAGS add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD} - COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND} + COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS};-stdlib=libc++" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} - -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_EXE_LINKER_FLAGS="-lc++abi" - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} - COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} + COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} + COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)" ) endforeach() diff --git a/tests/src/unit.cpp b/tests/src/unit.cpp index 93a934005..c05cde9c8 100644 --- a/tests/src/unit.cpp +++ b/tests/src/unit.cpp @@ -7,4 +7,22 @@ // SPDX-License-Identifier: MIT #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + +// libc++ annotates std::mutex for Clang's thread safety analysis, so -Weverything +// reports -Wthread-safety-negative for the locks in doctest's reporters, which are +// only compiled in this file. __has_warning keeps older Clang versions from +// reporting an unknown warning group. +#if defined(__clang__) && defined(__has_warning) + #if __has_warning("-Wthread-safety-negative") + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wthread-safety-negative" + #endif +#endif + #include "doctest_compatibility.h" + +#if defined(__clang__) && defined(__has_warning) + #if __has_warning("-Wthread-safety-negative") + #pragma clang diagnostic pop + #endif +#endif