AK: Pass AK::Format TypeErasedFormatParams by reference in AK::String

This silences a overeager warning in sonar cloud, warning that
slicing could occur with `VariadicFormatParams` which derives from
`TypeErasedFormatParams`.

Reference:
https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPBW3k92xXUF3qXTE&open=AXuVPBW3k92xXUF3qXTE

This is a continuation of f0b3aa0331.
This commit is contained in:
Brian Gianforcaro 2021-08-31 21:44:05 -07:00 committed by Andreas Kling
parent 8105d3f3d6
commit fee2a03ba9
Notes: sideshowbarker 2024-07-18 04:56:36 +09:00
2 changed files with 4 additions and 3 deletions

View file

@ -515,7 +515,7 @@ InputStream& operator>>(InputStream& stream, String& string)
}
}
String String::vformatted(StringView fmtstr, TypeErasedFormatParams params)
String String::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
{
StringBuilder builder;
vformat(builder, fmtstr, params);

View file

@ -265,12 +265,13 @@ public:
return String((const char*)buffer.data(), buffer.size(), should_chomp);
}
[[nodiscard]] static String vformatted(StringView fmtstr, TypeErasedFormatParams);
[[nodiscard]] static String vformatted(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
[[nodiscard]] static String formatted(CheckedFormatString<Parameters...>&& fmtstr, const Parameters&... parameters)
{
return vformatted(fmtstr.view(), VariadicFormatParams { parameters... });
VariadicFormatParams variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
template<typename T>