Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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

This patch simplifies a recursive use of a type trait to a C++17 fold
expression.
@llvmbot
Copy link
Member

llvmbot commented Oct 1, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/161479.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/Format.h (+3-11)
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 {

@kazutakahirata kazutakahirata merged commit 09dbb3e into llvm:main Oct 1, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250930_Support_Format_fold branch October 1, 2025 16:02
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…161479)

This patch simplifies a recursive use of a type trait to a C++17 fold
expression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants