summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/DeprecatedString.h2
-rw-r--r--AK/Format.h33
-rw-r--r--AK/String.h2
-rw-r--r--AK/StringBuilder.h4
-rw-r--r--Kernel/Bus/PCI/Device.h2
-rw-r--r--Kernel/KBufferBuilder.h2
-rw-r--r--Kernel/KString.h2
-rw-r--r--Userland/DevTools/UserspaceEmulator/Report.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ThrowableFormat.h2
-rw-r--r--Userland/Libraries/LibVideo/DecoderError.h2
10 files changed, 36 insertions, 17 deletions
diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h
index f9e09ae0f1..a77130161e 100644
--- a/AK/DeprecatedString.h
+++ b/AK/DeprecatedString.h
@@ -284,7 +284,7 @@ public:
template<typename... Parameters>
[[nodiscard]] static DeprecatedString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_parameters { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
diff --git a/AK/Format.h b/AK/Format.h
index a7a1080b9b..ed31bb4f4c 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -33,12 +33,26 @@ struct Formatter {
using __no_formatter_defined = void;
};
+enum AllowDebugOnlyFormatters {
+ No,
+ Yes
+};
+
template<typename T, typename = void>
inline constexpr bool HasFormatter = true;
template<typename T>
inline constexpr bool HasFormatter<T, typename Formatter<T>::__no_formatter_defined> = false;
+template<typename Formatter>
+inline constexpr bool is_debug_only_formatter()
+{
+ constexpr bool has_is_debug_only = requires(Formatter const& formatter) { formatter.is_debug_only(); };
+ if constexpr (has_is_debug_only)
+ return Formatter::is_debug_only();
+ return false;
+}
+
template<typename T>
concept Formattable = HasFormatter<T>;
@@ -270,7 +284,7 @@ ErrorOr<void> __format_value(TypeErasedFormatParams& params, FormatBuilder& buil
return formatter.format(builder, *static_cast<T const*>(value));
}
-template<typename... Parameters>
+template<AllowDebugOnlyFormatters allow_debug_formatters, typename... Parameters>
class VariadicFormatParams : public TypeErasedFormatParams {
public:
static_assert(sizeof...(Parameters) <= max_format_arguments);
@@ -278,6 +292,9 @@ public:
explicit VariadicFormatParams(Parameters const&... parameters)
: m_data({ TypeErasedParameter { &parameters, TypeErasedParameter::get_type<Parameters>(), __format_value<Parameters> }... })
{
+ constexpr bool any_debug_formatters = (is_debug_only_formatter<Formatter<Parameters>>() || ...);
+ static_assert(!any_debug_formatters || allow_debug_formatters == AllowDebugOnlyFormatters::Yes,
+ "You are attempting to use a debug-only formatter outside of a debug log! Maybe one of your format values is an ErrorOr<T>?");
this->set_parameters(m_data);
}
@@ -574,14 +591,14 @@ void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = fals
template<typename... Parameters>
void out(FILE* file, CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
vout(file, fmtstr.view(), variadic_format_params);
}
template<typename... Parameters>
void outln(FILE* file, CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
vout(file, fmtstr.view(), variadic_format_params, true);
}
@@ -625,7 +642,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
void dbgln(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
vdbgln(fmtstr.view(), variadic_format_params);
}
@@ -639,7 +656,7 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
void dmesgln(CheckedFormatString<Parameters...>&& fmt, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
vdmesgln(fmt.view(), variadic_format_params);
}
@@ -650,7 +667,7 @@ void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
void critical_dmesgln(CheckedFormatString<Parameters...>&& fmt, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::Yes, Parameters...> variadic_format_params { parameters... };
v_critical_dmesgln(fmt.view(), variadic_format_params);
}
#endif
@@ -695,7 +712,7 @@ struct Formatter<FormatString> : Formatter<StringView> {
template<typename... Parameters>
ErrorOr<void> format(FormatBuilder& builder, StringView fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
return vformat(builder, fmtstr, variadic_format_params);
}
ErrorOr<void> vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params);
@@ -722,6 +739,8 @@ struct Formatter<Error> : Formatter<FormatString> {
template<typename T, typename ErrorType>
struct Formatter<ErrorOr<T, ErrorType>> : Formatter<FormatString> {
+ static constexpr bool is_debug_only() { return true; }
+
ErrorOr<void> format(FormatBuilder& builder, ErrorOr<T, ErrorType> const& error_or)
{
if (error_or.is_error())
diff --git a/AK/String.h b/AK/String.h
index b0d4f3e2a1..3991922aa6 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -98,7 +98,7 @@ public:
template<typename... Parameters>
static ErrorOr<String> formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_parameters { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h
index 5e28ef0300..98299ea86b 100644
--- a/AK/StringBuilder.h
+++ b/AK/StringBuilder.h
@@ -33,7 +33,7 @@ public:
template<typename... Parameters>
ErrorOr<void> try_appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
return vformat(*this, fmtstr.view(), variadic_format_params);
}
ErrorOr<void> try_append(char const*, size_t);
@@ -57,7 +57,7 @@ public:
template<typename... Parameters>
void appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- VariadicFormatParams variadic_format_params { parameters... };
+ VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
MUST(vformat(*this, fmtstr.view(), variadic_format_params));
}
diff --git a/Kernel/Bus/PCI/Device.h b/Kernel/Bus/PCI/Device.h
index 9c1d1fa92e..61a713b664 100644
--- a/Kernel/Bus/PCI/Device.h
+++ b/Kernel/Bus/PCI/Device.h
@@ -48,7 +48,7 @@ void dmesgln_pci(Device const& device, AK::CheckedFormatString<Parameters...>&&
return;
if (builder.try_append(fmt.view()).is_error())
return;
- AK::VariadicFormatParams variadic_format_params { device.device_name(), device.pci_address(), parameters... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::Yes, StringView, Address, Parameters...> variadic_format_params { device.device_name(), device.pci_address(), parameters... };
vdmesgln(builder.string_view(), variadic_format_params);
}
diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h
index 426b7c8d9b..f5e6d10f48 100644
--- a/Kernel/KBufferBuilder.h
+++ b/Kernel/KBufferBuilder.h
@@ -37,7 +37,7 @@ public:
{
// FIXME: This really not ideal, but vformat expects StringBuilder.
StringBuilder builder;
- AK::VariadicFormatParams variadic_format_params { parameters... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
TRY(vformat(builder, fmtstr.view(), variadic_format_params));
return append_bytes(builder.string_view().bytes());
}
diff --git a/Kernel/KString.h b/Kernel/KString.h
index 2639f9617b..7905936dbe 100644
--- a/Kernel/KString.h
+++ b/Kernel/KString.h
@@ -26,7 +26,7 @@ public:
template<typename... Parameters>
[[nodiscard]] static ErrorOr<NonnullOwnPtr<KString>> formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
- AK::VariadicFormatParams variadic_format_parameters { parameters... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
diff --git a/Userland/DevTools/UserspaceEmulator/Report.h b/Userland/DevTools/UserspaceEmulator/Report.h
index a14e58d537..91a21c36d9 100644
--- a/Userland/DevTools/UserspaceEmulator/Report.h
+++ b/Userland/DevTools/UserspaceEmulator/Report.h
@@ -14,7 +14,7 @@ template<typename... Ts>
void reportln(StringView format, Ts... args)
{
if (g_report_to_debug) {
- AK::VariadicFormatParams variadic_format_params { args... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::Yes, Ts...> variadic_format_params { args... };
AK::vdbgln(format, variadic_format_params);
} else {
warnln(format, args...);
diff --git a/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h b/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h
index ec4d21f6de..2505d105bd 100644
--- a/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h
+++ b/Userland/Libraries/LibJS/Runtime/ThrowableFormat.h
@@ -19,7 +19,7 @@ template<typename... Args>
ThrowCompletionOr<DeprecatedString> deprecated_format(VM& vm, CheckedFormatString<Args...>&& fmtstr, Args const&... args)
{
StringBuilder builder;
- AK::VariadicFormatParams parameters { args... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Args...> parameters { args... };
TRY_OR_THROW_OOM(vm, vformat(builder, fmtstr.view(), parameters));
return builder.to_deprecated_string();
diff --git a/Userland/Libraries/LibVideo/DecoderError.h b/Userland/Libraries/LibVideo/DecoderError.h
index ed7731c909..402b9c8c22 100644
--- a/Userland/Libraries/LibVideo/DecoderError.h
+++ b/Userland/Libraries/LibVideo/DecoderError.h
@@ -43,7 +43,7 @@ public:
template<typename... Parameters>
static DecoderError format(DecoderErrorCategory category, CheckedFormatString<Parameters...>&& format_string, Parameters const&... parameters)
{
- AK::VariadicFormatParams variadic_format_params { parameters... };
+ AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
return DecoderError::with_description(category, DeprecatedString::vformatted(format_string.view(), variadic_format_params));
}