[llvm] 09dbb3e - [Support] Use a C++17 fold expression in a static_assert (NFC) (#161479)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 1 08:59:45 PDT 2025
Author: Kazu Hirata
Date: 2025-10-01T08:59:40-07:00
New Revision: 09dbb3e25444ec93b45320061932a1328f0d1ed8
URL: https://github.com/llvm/llvm-project/commit/09dbb3e25444ec93b45320061932a1328f0d1ed8
DIFF: https://github.com/llvm/llvm-project/commit/09dbb3e25444ec93b45320061932a1328f0d1ed8.diff
LOG: [Support] Use a C++17 fold expression in a static_assert (NFC) (#161479)
This patch simplifies a recursive use of a type trait to a C++17 fold
expression.
Added:
Modified:
llvm/include/llvm/Support/Format.h
Removed:
################################################################################
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