https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80265

--- Comment #11 from Pedro Alves <palves at redhat dot com> ---
Ok, so s[2] is not constant, while s[0] is, in that case.

AFAICS, changing constexpr_strlen to this:

constexpr size_t constexpr_strlen(const char* s)
{
  const char *p = s;

  while (__builtin_constant_p (*p) && *p)
    p++;
  if (!__builtin_constant_p (p[0]))
    return p - s + __builtin_strlen (p);
  return p - s;
}

makes it work as expected.  All the previous static_assert tests compile
without
error, and, we now get a call to strlen at run-time, AFAICS (I replaced that
__builtin_strlen call with a call to an "extern_strlen" function declared in
another compile unit instead to verify).

Could you confirm?

Reply via email to