[libcxx-commits] [PATCH] D127159: [libc++] Simplify the char_traits specializations

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 13 08:45:14 PDT 2022


ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM with comments.



================
Comment at: libcxx/include/__string/char_traits.h:181-183
+#endif
+  ::__builtin_memmove(__dest, __source, __n * sizeof(_CharT));
   return __dest;
----------------



================
Comment at: libcxx/include/__string/char_traits.h:207
+    char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
+        std::copy_n(__s2, __n, __s1);
+        return __s1;
----------------
ldionne wrote:
> philnik wrote:
> > mclow.lists wrote:
> > > Does this handle overlapping ranges? The old code does.
> > > 
> > > https://eel.is/c++draft/char.traits.require says it has to handle overlapping ranges.
> > While `std::copy_n` doesn't officially support overlapping ranges our implementation forwards trivial types to `__builtin_memmove`, which does handle them properly.
> Can you please add tests to cover that (or ensure we already do)?
> 
> Also, if we keep this, let's add a comment like `// our implementation of std::copy_n handles overlapping ranges`.
My comment about testing for overlapping ranges still holds. It should be simple to add.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127159/new/

https://reviews.llvm.org/D127159



More information about the libcxx-commits mailing list