mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
AK+Userland: Extend the compiletime format string check to other functions
Thanks to @trflynn89 for the neat implicit consteval ctor trick! This allows us to basically slap `CheckedFormatString` on any formatting function, and have its format argument checked at compiletime. Note that there is a validator bug where it doesn't parse inner replaced fields like `{:~>{}}` correctly (what should be 'left align with next argument as size' is parsed as `{:~>{` following a literal closing brace), so the compiletime checks are disabled on these temporarily by forcing them to be StringViews. This commit also removes the now unused `AK::StringLiteral` type (which was introduced for use with NTTP strings).
This commit is contained in:
parent
29c8d34be7
commit
347d741afb
6 changed files with 277 additions and 229 deletions
|
@ -565,36 +565,9 @@ using MakeIntegerSequence = decltype(make_integer_sequence_impl<T, N>());
|
|||
template<unsigned N>
|
||||
using MakeIndexSequence = MakeIntegerSequence<unsigned, N>;
|
||||
|
||||
template<unsigned long N>
|
||||
struct StringLiteral {
|
||||
constexpr StringLiteral(const char (&in)[N])
|
||||
: data {}
|
||||
, size { N }
|
||||
{
|
||||
for (unsigned long i = 0; i < N; ++i)
|
||||
data[i] = in[i];
|
||||
}
|
||||
|
||||
template<unsigned long Nx>
|
||||
constexpr StringLiteral& operator=(const StringLiteral<Nx>& other)
|
||||
{
|
||||
static_assert(Nx <= N, "Storing a string literal in a smaller one");
|
||||
for (unsigned long i = 0; i < Nx; ++i)
|
||||
data[i] = other[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned long Nx>
|
||||
constexpr StringLiteral& operator=(const char (&other)[Nx])
|
||||
{
|
||||
static_assert(Nx <= N, "Storing a string literal in a smaller one");
|
||||
for (unsigned long i = 0; i < Nx; ++i)
|
||||
data[i] = other[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
char data[N];
|
||||
unsigned long size;
|
||||
template<typename T>
|
||||
struct IdentityType {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -608,6 +581,7 @@ using AK::declval;
|
|||
using AK::DependentFalse;
|
||||
using AK::exchange;
|
||||
using AK::forward;
|
||||
using AK::IdentityType;
|
||||
using AK::IndexSequence;
|
||||
using AK::IntegerSequence;
|
||||
using AK::is_trivial;
|
||||
|
@ -630,6 +604,5 @@ using AK::max;
|
|||
using AK::min;
|
||||
using AK::move;
|
||||
using AK::RemoveConst;
|
||||
using AK::StringLiteral;
|
||||
using AK::swap;
|
||||
using AK::Void;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue