[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 14:31:58 PDT 2024


================
@@ -102,7 +102,7 @@ struct __aliasing_iterator_wrapper {
 
     _LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT {
       _Alias __val;
-      __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type));
+      __builtin_memcpy(&__val, static_cast<const void*>(std::__to_address(__base_)), sizeof(value_type));
----------------
serge-sans-paille wrote:

There's one thing I don't understand: my understanding is that passing a pointer to a non-trivially copyable type to memcpy first or second argument is UB and ` _BaseIter` maybe a non-trivially copyable type, so what happens then?

https://github.com/llvm/llvm-project/pull/111434


More information about the cfe-commits mailing list