<div dir="ltr">We could probably write and use our own constexpr strlen for MSVC, but we'd lose out on the CRT's optimized implementation of strlen.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 24, 2016 at 6:59 AM, Malcolm Parsons via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
There is a desire to be able to create constexpr StringRefs to avoid<br>
static initializers for global tables of/containing StringRefs.<br>
<br>
Creating constexpr StringRefs isn't trivial as strlen isn't portably<br>
constexpr and std::char_traits<char>::length is only constexpr in<br>
C++17.<br>
<br>
Alp Toker tried to create constexpr StringRefs for strings literals by<br>
subclassing StringRef:<br>
<a href="https://reviews.llvm.org/rL200187" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>rL200187</a><br>
This is a verbose change where needed at string literal call sites.<br>
<br>
Mehdi AMINI tried to add a constexpr constructor for string literals<br>
by making the constructor from const char * explicit:<br>
<a href="https://reviews.llvm.org/D25639" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D25639</a><br>
This is a verbose change at every non-literal call site.<br>
This only works with assignment syntax.<br>
<br>
I've suggested using a user-defined literal:<br>
<a href="https://reviews.llvm.org/D26332" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D26332</a><br>
This is a small change where needed at string literal call sites.<br>
C++17 adds a UDL for std::string_view, so it's not an unusual idea.<br>
There is resistance to using a UDL as they can introduce a surprising<br>
and novel syntax for calling functions.<br>
<br>
Comments?<br>
<br>
Other options?<br>
<br>
Thanks,<br>
<span class="HOEnZb"><font color="#888888">--<br>
Malcolm Parsons<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</font></span></blockquote></div><br></div>