[llvm-dev] RFC: Constructing StringRefs at compile time
Malcolm Parsons via llvm-dev
llvm-dev at lists.llvm.org
Thu Nov 24 06:59:25 PST 2016
There is a desire to be able to create constexpr StringRefs to avoid
static initializers for global tables of/containing StringRefs.
Creating constexpr StringRefs isn't trivial as strlen isn't portably
constexpr and std::char_traits<char>::length is only constexpr in
Alp Toker tried to create constexpr StringRefs for strings literals by
This is a verbose change where needed at string literal call sites.
Mehdi AMINI tried to add a constexpr constructor for string literals
by making the constructor from const char * explicit:
This is a verbose change at every non-literal call site.
This only works with assignment syntax.
I've suggested using a user-defined literal:
This is a small change where needed at string literal call sites.
C++17 adds a UDL for std::string_view, so it's not an unusual idea.
There is resistance to using a UDL as they can introduce a surprising
and novel syntax for calling functions.
More information about the llvm-dev