[Bug libstdc++/93059] char and char8_t does not talk with each other with memcpy. std::copy std::copy_n, std::fill, std::fill_n, std::uninitialized_copy std::uninitialized_copy_n, std::fill, std::uninitialized_fill_n fails to convert to memxxx functions

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 26 14:40:00 GMT 2020


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

--- Comment #35 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Bernd Edlinger from comment #26)
> (In reply to fdlbxtqi from comment #2)
> > Also find a bug of __memmove
> > 
> >   /*
> >    * A constexpr wrapper for __builtin_memmove.
> >    * @param __num The number of elements of type _Tp (not bytes).
> >    */
> >   template<bool _IsMove, typename _Tp>
> >     _GLIBCXX14_CONSTEXPR
> >     inline void*
> >     __memmove(_Tp* __dst, const _Tp* __src, size_t __num)
> >     {
> > #ifdef __cpp_lib_is_constant_evaluated
> >       if (std::is_constant_evaluated())
> > 	{
> > 	  for(; __num > 0; --__num)
> > 	    {
> > 	      if constexpr (_IsMove)
> > 		*__dst = std::move(*__src);
> > 	      else
> > 		*__dst = *__src;
> > 	      ++__src;
> > 	      ++__dst;
> > 	    }
> > 	  return __dst;
> > 	}
> >       else
> > #endif
> > 	return __builtin_memmove(__dst, __src, sizeof(_Tp) * __num);
> >       return __dst;
> >     }
> > 
> > The last 2nd line return __dst is wrong. It should not exist.
> 
> Sorry, I don't know what this function is all about.
> But to me the code in the ifdef looks totally bogus.
> First it returns __dst+__num, while memmove is sopposed
> to return __dst, and is is somehow clear that
> __dst and __src do not overlap?

Yes, it was only used by std::copy and std::move and they require that __dst is
not in the range [__src, __src+__num). It's allowed for __dst+__num to be in
that range, but the function works correctly in that case anyway.

The return value wasn't used.

But I've removed the entire function, so it doesn't matter now.


More information about the Gcc-bugs mailing list