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();
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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits