<div dir="ltr">+ Eric (for standard library knowledge) & Richard (for general C++-ery).<br><br>I can't say I know much about __cpp_lib_constexpr_char_traits - got any reference on how widely supported/implemented that is?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 6, 2020 at 10:17 AM Dan Bailey via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-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 dir="ltr">Hi,<div><br></div><div>When trying to compile LLVM using GCC 5.1 => GCC 7.2 (inclusive) with -std=c++1z, using StringRef errors due to the lack of  a constexpr std::char_traits<char>::length():</div><div><br></div><div><font face="monospace">.../include/llvm/ADT/StringRef.h:85:44: <font color="#ff0000"><b>error</b></font>: call to non-constexpr function ‘static std::size_t std::char_traits<char>::length(const char_type*)’<br>       return std::char_traits<char>::length(Str);<br>              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~</font><br><div><br></div><div>Looking into the issue, StringRef.h uses this logic to gate against using constexpr char_traits:</div><div><br></div><div><font face="monospace">#if <b>__cplusplus</b> > 201402L<br>      return std::char_traits<char>::length(Str);<br></font></div><div><font face="monospace">#elif ...</font></div><div><br></div><div>However for the GCC version range mentioned above, the -std=c++1z flag generates __cplusplus 201500L or higher despite char_traits not being constexpr.</div><div><br></div><div>I think the correct thing to do here might be to use the feature macro instead:</div><div><br></div><div><font face="monospace">#if <b>__cpp_lib_constexpr_char_traits</b><br></font></div><div><font face="monospace">      return std::char_traits<char>::length(Str);<br></font></div><div><font face="monospace">#elif ...</font></div><div><br></div><div>Any thoughts?</div><div><br></div><div>Thanks,</div></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><pre>Dan Bailey        | R&D               | ILM Vancouver<br><a href="mailto:danbailey@ilm.com" target="_blank">danbailey@ilm.com</a> | 415 746-XXXX Desk | 778 882-XXXX Cell</pre></div></div></div></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>