[clang] [compiler-rt] [libcxx] [llvm] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
Carlos Galvez via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 04:12:16 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));
----------------
carlosgalvezp wrote:
If we take the perspective of "anything not explicitly defined in the Standard is undefined", then the Standard never specifies the behavior of calling std::memcpy on non-trivially copyable types. It only specifies the behavior for trivially-copyable types in [[basic.types]#2](https://eel.is/c++draft/basic.types.general#2) and [[basic.types]#3](https://eel.is/c++draft/basic.types.general#3).
But if we look at this with a more pragmatic look, I guess the real problem is bypassing the `dst` class constructor, potentially breaking invariants and causing UB due to that. This is perhaps why GCC only warns about the `dst` type being non-trivial. It does **not** warn about the `src` type (which we are discussing here).
So maybe we could tweak the warning to only warn on the `dst` type instead?
https://github.com/llvm/llvm-project/pull/111434
More information about the llvm-commits
mailing list