[WTF] Ensure ASCIILiteral is ASCII characters at compile time
Created attachment 402438 [details] Patch
Comment on attachment 402438 [details] Patch r=me. ラーメン食べたい。
Comment on attachment 402438 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402438&action=review > Source/WTF/wtf/text/ASCIILiteral.h:64 > + ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); Since this is constexpr, is there a reason why we only want this for ASSERT_ENABLED? Why not have RELEASE_ASSERT_UNDER_CONSTEXPR_CONTEXT this?
Comment on attachment 402438 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402438&action=review >> Source/WTF/wtf/text/ASCIILiteral.h:64 >> + ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); > > Since this is constexpr, is there a reason why we only want this for ASSERT_ENABLED? Why not have RELEASE_ASSERT_UNDER_CONSTEXPR_CONTEXT this? Discussed with Mark on Slack, this function can be called in non-constexpr context, like, auto string = "Hey"_s; // instead of constexpr string = "Hey"_s; in non global code. So, this is safer for accidental runtime checks.
Committed r263341: <https://trac.webkit.org/changeset/263341> All reviewed patches have been landed. Closing bug and clearing flags on attachment 402438 [details].
<rdar://problem/64585669>
Comment on attachment 402438 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=402438&action=review > Source/WTF/ChangeLog:12 > + auto globalVariable = "ã©ã¼ã¡ã³ (Ramen in Japanese)"_s; As a ramen enthusiast, I like this example in the commit log ^_^ 🍜️♥️
Very very happy to see this change go in.
Is there some way to make this even more strongly guaranteed to be done at compile time? I assume the answer is no, but obviously we want to compile errors with a poorly formed literal, not a runtime check if it happens to be used in a non-constexpr context.
(In reply to Darin Adler from comment #9) > Is there some way to make this even more strongly guaranteed to be done at > compile time? I assume the answer is no, but obviously we want to compile > errors with a poorly formed literal, not a runtime check if it happens to be > used in a non-constexpr context. This is the purpose of consteval in C++20! https://en.cppreference.com/w/cpp/language/consteval I can't wait to use C++20 :D