[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 28 07:03:00 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));
----------------
AaronBallman wrote:
If the goal is to inspect the bytes of the source object, then it's not UB because that inspection would be happening on a byte-by-byte level and not on the value representation level. So the `memcpy` itself is not really UB because it is only touching on a byte-by-byte level. Where I think the UB comes in is when someone attempts to use the `_Alias` object constructed by the call to `memcpy` because that object may not have a valid representation.
https://eel.is/c++draft/basic.indet#1.sentence-3
https://eel.is/c++draft/conv.lval#3.4
https://github.com/llvm/llvm-project/pull/111434
More information about the cfe-commits
mailing list