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: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 31 Mar 2017 13:07:18 +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 #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Perhaps we then need some helper function partly similar to cxx_eval_array_ref,
that would for an object (or address of it?) and some uhwi index attempt to
return some byte from the object, and then if the middle-end folding doesn't
yield anything, handle these builtins by using that helper in a loop to grab
bytes from one or two input strings, then perform the needed action on them as
if we have open-coded those routines in trivial C loops.
As even
constexpr char
foo (int x)
{
char a[] = { 'a', 'b', 'c', 'd', '\0' };
char *b = &a[0];
return ((unsigned char *)b)[x];
}
constexpr char a = foo (0);
is rejected, I think we can't use the existing routines here though, we want to
be able to access bytes of anything initialized.