From 459e35f2619455fec980be7af21e690d12ea3500 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 19 Jul 2021 14:10:37 -0700 Subject: [PATCH] Static assert that LiteralStringRef arg is literal string --- flow/Arena.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flow/Arena.h b/flow/Arena.h index d752baedf0..185626ffa9 100644 --- a/flow/Arena.h +++ b/flow/Arena.h @@ -662,7 +662,15 @@ struct Traceable> : std::conditional::value, std::tru static std::string toString(const Standalone& value) { return Traceable::toString(value); } }; -#define LiteralStringRef(str) StringRef((const uint8_t*)(str), sizeof((str)) - 1) +namespace literal_string_ref { +template +StringRef LiteralStringRefHelper(const char* str) { + static_assert(std::is_same_v, "Argument to LiteralStringRef must be a literal string"); + return StringRef(reinterpret_cast(str), Size); +} +} // namespace literal_string_ref +#define LiteralStringRef(str) literal_string_ref::LiteralStringRefHelper(str) + inline StringRef operator"" _sr(const char* str, size_t size) { return StringRef(reinterpret_cast(str), size); }