From ccb419ca6496fd390b9f547455ddd622d3f8ae1a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 28 Sep 2026 18:22:16 +0200 Subject: [PATCH] Fix clang-tidy and clang 6 in the #5066 regression test ci_clang_tidy asked for emplace_back instead of push_back. The push_back is the point of the test: #5066 is about the implicit conversion from json to the vector's value type, which emplace_back would bypass. Silence the check on that line. clang 5 and 6 cannot instantiate std::variant from libstdc++ 10's ("cannot cast private base class"), which broke ci_test_compilers_clang (6). Tested with the CI images: clang 7 to 11 compile and pass, including clang 11 with libstdc++ 10. Skip the runtime check for clang before 7; the static_assert still runs. Signed-off-by: Niels Lohmann --- tests/src/unit-regression2.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index a2a919ec8..d10a634a2 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -775,9 +775,14 @@ TEST_CASE("regression tests 2") static_assert(!nlohmann::detail::is_detected>::value, "std::variant must not be retrievable via get<>()"); + // clang before 7 cannot instantiate libstdc++'s std::variant +#if !(defined(__clang__) && __clang_major__ < 7) + // push_back, not emplace_back: #5066 needs the implicit conversion + // from json to the vector's value type std::vector> v; - v.push_back(json(1)); + v.push_back(json(1)); // NOLINT(hicpp-use-emplace,modernize-use-emplace) CHECK(std::get<0>(v[0]) == 1); +#endif } #endif }