From f31bd190b0f746a8e304a4eeb79ce9c002e656d0 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 2 Feb 2023 10:48:11 -0500 Subject: [PATCH] AK: Ensure string types are actually considered hash-compatible The AnyString concept is currently broken because it checks whether a StringView is constructible from a type T. The StringView constructors, however, only accept constant rvalue references - i.e. `T const&`. This also adds a test to ensure this continues to work. --- AK/Concepts.h | 2 +- Tests/AK/TestStringUtils.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/AK/Concepts.h b/AK/Concepts.h index f3966a1e84c..5b753050d9f 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -49,7 +49,7 @@ template concept DerivedFrom = IsBaseOf; template -concept AnyString = IsConstructible; +concept AnyString = IsConstructible const&>; template concept HashCompatible = IsHashCompatible, Detail::Decay>; diff --git a/Tests/AK/TestStringUtils.cpp b/Tests/AK/TestStringUtils.cpp index 93b4c451573..90090acf106 100644 --- a/Tests/AK/TestStringUtils.cpp +++ b/Tests/AK/TestStringUtils.cpp @@ -6,9 +6,33 @@ #include +#include +#include +#include +#include #include #include +TEST_CASE(hash_compatible) +{ + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); + + static_assert(AK::Concepts::HashCompatible); + static_assert(AK::Concepts::HashCompatible); +} + TEST_CASE(matches_null) { EXPECT(AK::StringUtils::matches(StringView(), StringView()));