From 8732bd9de16b52bc521f49f416ceeda368f357c7 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 10 Sep 2026 21:26:37 +0000 Subject: [PATCH] Replace C-style variadic with a concept (#7761) clang-tidy 24 warns on C-style variadics, and we don't need to use one here anymore. Instead of a function call with an argument list, use a concept to determine if a type can be list initialized. --- common/struct_reflection.h | 10 ++-------- common/struct_reflection_test.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/common/struct_reflection.h b/common/struct_reflection.h index 8cc01dca05e0..7d19dd796e5c 100644 --- a/common/struct_reflection.h +++ b/common/struct_reflection.h @@ -55,13 +55,7 @@ struct AnyField { // Detector for whether we can list-initialize T from the given list of fields. template -constexpr auto CanListInitialize(decltype(T{Fields()...})* /*unused*/) -> bool { - return true; -} -template -constexpr auto CanListInitialize(...) -> bool { - return false; -} +concept CanListInitialize = requires { T{Fields()...}; }; #pragma clang diagnostic pop @@ -72,7 +66,7 @@ constexpr auto CanListInitialize(...) -> bool { // 2) Add more AnyFields until we can't initialize any more. template constexpr auto CountFields() -> int { - if constexpr (CanListInitialize(nullptr)) { + if constexpr (CanListInitialize) { return CountFields>(); } else if constexpr (AnyWorkedSoFar) { constexpr int NumFields = sizeof...(Fields) - 1; diff --git a/common/struct_reflection_test.cpp b/common/struct_reflection_test.cpp index 39b58d410a75..2104aab1c2fd 100644 --- a/common/struct_reflection_test.cpp +++ b/common/struct_reflection_test.cpp @@ -53,17 +53,17 @@ TEST(StructReflectionTest, CanListInitialize) { { using Type = OneField; using Field = Internal::AnyField; - static_assert(Internal::CanListInitialize(nullptr)); - static_assert(Internal::CanListInitialize(nullptr)); - static_assert(!Internal::CanListInitialize(0)); + static_assert(Internal::CanListInitialize); + static_assert(Internal::CanListInitialize); + static_assert(!Internal::CanListInitialize); } { using Type = OneFieldNoDefaultConstructor; using Field = Internal::AnyField; - static_assert(!Internal::CanListInitialize(0)); - static_assert(Internal::CanListInitialize(nullptr)); - static_assert(!Internal::CanListInitialize(0)); + static_assert(!Internal::CanListInitialize); + static_assert(Internal::CanListInitialize); + static_assert(!Internal::CanListInitialize); } }