[llvm] [Support] Use a C++17 fold expression in a static_assert (NFC) (PR #161479)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 22:49:38 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/161479
More information about the llvm-commits
mailing list