<div dir="ltr"><div dir="ltr"><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">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="gmail-m_-5423907003437222575WordSection1">
<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></div></div><br></blockquote><div><br></div><div>Well, sure.</div><div>The global variable s is not constexpr in your example.</div><div><br></div><div>-- Marshall</div><div> </div></div></div>