[PATCH] D109862: Don't diagnose unused but set when the Cleanup attribute is used.
Michael Benfield via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 15 16:47:18 PDT 2021
mbenfield created this revision.
mbenfield added a reviewer: dblaikie.
mbenfield requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This applies to -Wunused-but-set-variable and
-Wunused-but-set-parameter.
This addresses bug 51865.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109862
Files:
clang/lib/Sema/SemaDecl.cpp
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@
}
void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
- // If it's not referenced, it can't be set.
- if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr<UnusedAttr>())
+ // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+ // it's not really unused.
+ if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr<UnusedAttr>() ||
+ VD->hasAttr<CleanupAttr>())
return;
const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109862.372837.patch
Type: text/x-patch
Size: 696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210915/f1e98284/attachment.bin>
More information about the cfe-commits
mailing list