<div dir="auto">I think __builtin_strlen is a red herring here. This just seems like a general issue with GCC's constexpr implementation of strings.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 10, 2019, 1:10 AM Zoe Carver via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">"__builtin_strlen" works with GCC 7.x and up and clang 6.x and up. Here is a Godbolt: <a href="https://godbolt.org/z/G9NpAX" target="_blank" rel="noreferrer">https://godbolt.org/z/G9NpAX</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 9, 2019 at 1:50 PM Yan  Yichen via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank" rel="noreferrer">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="m_-8609902561425268251gmail-m_2357375360716072710WordSection1">
<p class="MsoNormal"><span style="color:rgb(31,73,125)">I got a little bit confused trying to get a repro of __builtin_strlen in libc++ with gcc.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">At least the behavior of __builtin_strlen is different in clang and gcc.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">This passed<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">g++ -o /dev/null -std=c++17 --compile test2.cc<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">while this failed<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">clang++ -o /dev/null -std=c++17 --compile test2.cc<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">with error messages:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">test2.cc:6:19: error: static_assert expression is not an integral constant expression<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">    static_assert(!test(s));<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">                  ^~~~~~~~<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">test2.cc:3:12: note: read of non-constexpr variable 's' is not allowed in a constant expression<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">    return __builtin_strlen(s);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">           ^<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">test2.cc:6:20: note: in call to 'test(&s[0])'<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">    static_assert(!test(s));<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">                   ^<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">1 error generated.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">For one same file:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">const char s[] = "";<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">constexpr int test(const char* s) {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">    return __builtin_strlen(s);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">constexpr void __main() {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">    static_assert(!test(s));<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><a name="m_-8609902561425268251_m_2357375360716072710__MailOriginal" rel="noreferrer"><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">Hmmm...  I think __builtin_strlen is constexpr on gcc.<u></u><u></u></span></a></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">Looking at a more minimal case:<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p style="margin:0in 0in 0.0001pt"><span><b><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:rgb(155,35,147)">int</span></b></span><span><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:black">
 main() { </span></span><span><b><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:rgb(155,35,147)">static_assert</span></b></span><span><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:black">(!__builtin_strlen(</span></span><span><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:rgb(196,26,22)">""</span></span><span><span lang="DE-CH" style="font-size:9pt;font-family:Menlo,serif;color:black">));
 }<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">It compiles fine under:<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">gcc 9.2, libstdc++<u></u><u></u></span></span></p>
</div>
<div>
<p style="margin:0in 0in 0.0001pt"><span><span lang="DE-CH" style="font-size:8.5pt;font-family:"Source Code Pro",serif;color:black">/usr/local/gcc/bin/g++-9 -std=c++17 a.cpp<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">clang 8, libc++<u></u><u></u></span></span></p>
</div>
<div>
<p style="margin:0in 0in 0.0001pt"><span><span lang="DE-CH" style="font-size:8.5pt;font-family:"Source Code Pro",serif;color:black">/usr/local/clang/bin/clang++ -std=c++17 a.cpp<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u> <u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif">gcc 9.2, libc++<u></u><u></u></span></span></p>
</div>
<div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:8.5pt;font-family:"Source Code Pro",serif;color:black">/usr/local/gcc/bin/g++-9 -nostdinc++ -I /usr/local/clang/include/c++/v1 -nodefaultlibs -lc++ -lc++abi -lm
 -lc -lgcc -std=c++17 a.cpp</span></span><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"><u></u><u></u></span></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif"> </span></span><span lang="DE-CH" style="font-size:12pt;font-family:"Times New Roman",serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
</div>
</div>

_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank" rel="noreferrer">libcxx-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br>
</blockquote></div>
_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank" rel="noreferrer">libcxx-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br>
</blockquote></div>