[llvm] [Support] Use a C++17 fold expression in a static_assert (NFC) (PR #161479)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 22:49:04 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/161479

This patch simplifies a recursive use of a type trait to a C++17 fold
expression.


>From f69febc9b11bf67bba4fe3c60cb0d63c3d8eb471 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 30 Sep 2025 00:12:03 -0700
Subject: [PATCH] [Support] Use a C++17 fold expression in a static_assert
 (NFC)

This patch simplifies a recursive use of a type trait to a C++17 fold
expression.
---
 llvm/include/llvm/Support/Format.h | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/llvm/include/llvm/Support/Format.h b/llvm/include/llvm/Support/Format.h
index 2553002b37899..34b224dba5407 100644
--- a/llvm/include/llvm/Support/Format.h
+++ b/llvm/include/llvm/Support/Format.h
@@ -78,16 +78,6 @@ class LLVM_ABI format_object_base {
 /// printed, this synthesizes the string into a temporary buffer provided and
 /// returns whether or not it is big enough.
 
-// Helper to validate that format() parameters are scalars or pointers.
-template <typename... Args> struct validate_format_parameters;
-template <typename Arg, typename... Args>
-struct validate_format_parameters<Arg, Args...> {
-  static_assert(std::is_scalar_v<Arg>,
-                "format can't be used with non fundamental / non pointer type");
-  validate_format_parameters() { validate_format_parameters<Args...>(); }
-};
-template <> struct validate_format_parameters<> {};
-
 template <typename... Ts>
 class format_object final : public format_object_base {
   std::tuple<Ts...> Vals;
@@ -105,7 +95,9 @@ class format_object final : public format_object_base {
 public:
   format_object(const char *fmt, const Ts &... vals)
       : format_object_base(fmt), Vals(vals...) {
-    validate_format_parameters<Ts...>();
+    static_assert(
+        (std::is_scalar_v<Ts> && ...),
+        "format can't be used with non fundamental / non pointer type");
   }
 
   int snprint(char *Buffer, unsigned BufferSize) const override {



More information about the llvm-commits mailing list