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

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 06:19:26 PDT 2024


philnik777 wrote:

> > ACK. Not a standard requirement though, is it?
> 
> Correct, it's only UB on non-trivially-copyable. My point was more about if we want to be consistent with GCC or not. I don't have any strong opinion on that.

I can see an argument that a user probably is doing something wrong if they `memset` a non-trivial type, especially since compilers are perfectly capable of optimizing zero-initializing loops into `memset`s. For `memcpy`/`memmove` we should definitely only diagnose non-trivially copyable cases, since it's quite a common optimization to `memcpy` trivially copyable objects.

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


More information about the cfe-commits mailing list