Skip to content

Conversation

kazutakahirata
Copy link
Contributor

This patch uses llvm::is_detected to replace the old SFINAE-based
approach.

This patch uses llvm::is_detected to replace the old SFINAE-based
approach.
@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

This patch uses llvm::is_detected to replace the old SFINAE-based
approach.


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

1 Files Affected:

  • (modified) llvm/include/llvm/Support/FormatVariadicDetails.h (+3-6)
diff --git a/llvm/include/llvm/Support/FormatVariadicDetails.h b/llvm/include/llvm/Support/FormatVariadicDetails.h
index b85a4f6065195..1879a9844030c 100644
--- a/llvm/include/llvm/Support/FormatVariadicDetails.h
+++ b/llvm/include/llvm/Support/FormatVariadicDetails.h
@@ -66,13 +66,10 @@ template <class T> class has_FormatProvider {
   typedef void (*Signature_format)(const Decayed &, llvm::raw_ostream &,
                                    StringRef);
 
-  template <typename U>
-  static char test(SameType<Signature_format, &U::format> *);
-
-  template <typename U> static double test(...);
+  template <typename U> using check = SameType<Signature_format, &U::format>;
 
-  static bool const value =
-      (sizeof(test<llvm::format_provider<Decayed>>(nullptr)) == 1);
+  static constexpr bool value =
+      llvm::is_detected<check, llvm::format_provider<Decayed>>::value;
 };
 
 // Test if raw_ostream& << T -> raw_ostream& is findable via ADL.

@kazutakahirata kazutakahirata merged commit 7d949ee into llvm:main Sep 14, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250914_has_FormatProvider branch September 14, 2025 21:04
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.

3 participants