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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 06:39:41 PDT 2024


================
@@ -8899,18 +8899,42 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
           << ArgIdx << FnName << PointeeTy
           << Call->getCallee()->getSourceRange());
     else if (const auto *RT = PointeeTy->getAs<RecordType>()) {
+
+      auto IsTriviallyCopyableCXXRecord = [](auto const *RT) {
----------------
AaronBallman wrote:

```suggestion
      auto IsTriviallyCopyableCXXRecord = [](const RecordType *RT) {
```
Do not use `auto` when there's only one type this can be called with (I just spent a lot of time writing comments that I had to delete because this can only accept a `RecordType`).

Actually, I don't think we even need the lambda. You could precalculate this as a local variable:
```
bool IsTriviallyCopyableCXXRecord = false;
if (const auto *RD = RT->getAsCXXRecordDecl())
  IsTriviallyCopyableCXXRecord = RD->isTriviallyCopyable();
```
should suffice. (The call should return `false` if the record has no definition because that's an incomplete type but that's a good test case to ensure we have.)

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


More information about the cfe-commits mailing list