[llvm] [Support] Use a C++17 fold expression in ScopedPrinter.h (NFC) (PR #161778)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 3 08:36:32 PDT 2025


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/161778

>From ef1403ccd97fda282758526ca19493c6b56f073e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 30 Sep 2025 23:02:10 -0700
Subject: [PATCH 1/2] [Support] Use a C++17 fold expression in ScopedPrinter.h
 (NFC)

---
 llvm/include/llvm/Support/ScopedPrinter.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h
index a08cc8fd31fd2..ce125f60fd44c 100644
--- a/llvm/include/llvm/Support/ScopedPrinter.h
+++ b/llvm/include/llvm/Support/ScopedPrinter.h
@@ -454,14 +454,10 @@ class LLVM_ABI ScopedPrinter {
   virtual raw_ostream &getOStream() { return OS; }
 
 private:
-  template <typename T> void printVersionInternal(T Value) {
+  template <typename T, typename... TArgs>
+  void printVersionInternal(T Value, TArgs... Args) {
     getOStream() << Value;
-  }
-
-  template <typename S, typename T, typename... TArgs>
-  void printVersionInternal(S Value, T Value2, TArgs... Args) {
-    getOStream() << Value << ".";
-    printVersionInternal(Value2, Args...);
+    ((getOStream() << '.' << Args), ...);
   }
 
   static bool flagName(const FlagEntry &LHS, const FlagEntry &RHS) {

>From 1fa44dafe1ffc2fc0df66572a17cd5fad76576be Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 3 Oct 2025 08:36:05 -0700
Subject: [PATCH 2/2] Address a comment.

---
 llvm/include/llvm/Support/ScopedPrinter.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h
index ce125f60fd44c..94080e85a9048 100644
--- a/llvm/include/llvm/Support/ScopedPrinter.h
+++ b/llvm/include/llvm/Support/ScopedPrinter.h
@@ -284,9 +284,11 @@ class LLVM_ABI ScopedPrinter {
     startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n';
   }
 
-  template <typename... T> void printVersion(StringRef Label, T... Version) {
+  template <typename T, typename... TArgs>
+  void printVersion(StringRef Label, T MajorVersion, TArgs... MinorVersions) {
     startLine() << Label << ": ";
-    printVersionInternal(Version...);
+    getOStream() << MajorVersion;
+    ((getOStream() << '.' << MinorVersions), ...);
     getOStream() << "\n";
   }
 
@@ -454,12 +456,6 @@ class LLVM_ABI ScopedPrinter {
   virtual raw_ostream &getOStream() { return OS; }
 
 private:
-  template <typename T, typename... TArgs>
-  void printVersionInternal(T Value, TArgs... Args) {
-    getOStream() << Value;
-    ((getOStream() << '.' << Args), ...);
-  }
-
   static bool flagName(const FlagEntry &LHS, const FlagEntry &RHS) {
     return LHS.Name < RHS.Name;
   }



More information about the llvm-commits mailing list