[Bug libstdc++/122907] [15/16 Regression] std::copy incorrectly uses memcpy when copying from signed or unsigned char buffer to bool buffer

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 1 11:07:52 GMT 2025


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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Now, perhaps because __memcpyable_integer<_Tp>::__width is 0 or some multiple
of __CHAR_BIT__, perhaps easiest fix would be to arrange for this __width on
bool to be 1 rather than __CHAR_BIT__ or more.
So, add
  // Cannot memcpy between bool and non-bool in either direction.
  template<>
    struct __memcpyable_integer<bool>
    { enum { __width = 1 }; };

  template<>
    struct __memcpyable_integer<const bool>
    { enum { __width = 1 }; };
?


More information about the Gcc-bugs mailing list