This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80265] __builtin_{memcmp,memchr,strlen} are not usable in constexpr functions
- From: "palves at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 23 Mar 2018 12:58:33 +0000
- Subject: [Bug c++/80265] __builtin_{memcmp,memchr,strlen} are not usable in constexpr functions
- Auto-submitted: auto-generated
- References: <bug-80265-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80265
--- Comment #30 from Pedro Alves <palves at redhat dot com> ---
> I suspect that wouldn't work, because we'd need to check whether the
> elements the iterator range point-to are themselves constant.
I would like to add that the char_traits trick handles this by doing exactly
that, checking whether all elements in the string/array are constant
(__constant_string_p/__constant_char_array_p), before deferring to the naive
for loop; a __constexpr_memcmp would do the same before falling back to
__builtin_memcmp. In my testing back then, the compiler/optimizer always
folded away these loops.