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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-09-21
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, that seems undesirable.

Reduced:

template<typename T>
void to_array(T& from)
{
  T to;
  __builtin_memcpy(&to, &from, sizeof(T));
}

struct incomplete;

template<class T>
struct holder {
    T t;
};

using validator = holder<incomplete>*;

int main()
{
    validator a[1]{};
    ::to_array(a);
}

Casting the arguments to void avoids the problem:

  __builtin_memcpy((void*)&to, (void*)&from, sizeof(T));

Reply via email to