[clang] 85fce44 - [Sema] Simplify ShouldDiagnoseUnusedDecl, NFC
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 29 09:43:35 PDT 2020
Author: Aaron Puchert
Date: 2020-08-29T18:42:58+02:00
New Revision: 85fce449dc43447bf9d75163bda81e157f5b73e7
URL: https://github.com/llvm/llvm-project/commit/85fce449dc43447bf9d75163bda81e157f5b73e7
DIFF: https://github.com/llvm/llvm-project/commit/85fce449dc43447bf9d75163bda81e157f5b73e7.diff
LOG: [Sema] Simplify ShouldDiagnoseUnusedDecl, NFC
Instead of writing to a flag and then returning based on that flag we
can also return directly. The flag name also doesn't provide additional
information, it just reflects the name of the function (isReferenced).
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fba590f44c20..a9e6113dc7bb 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1763,25 +1763,20 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
if (D->isInvalidDecl())
return false;
- bool Referenced = false;
if (auto *DD = dyn_cast<DecompositionDecl>(D)) {
// For a decomposition declaration, warn if none of the bindings are
// referenced, instead of if the variable itself is referenced (which
// it is, by the bindings' expressions).
- for (auto *BD : DD->bindings()) {
- if (BD->isReferenced()) {
- Referenced = true;
- break;
- }
- }
+ for (auto *BD : DD->bindings())
+ if (BD->isReferenced())
+ return false;
} else if (!D->getDeclName()) {
return false;
} else if (D->isReferenced() || D->isUsed()) {
- Referenced = true;
+ return false;
}
- if (Referenced || D->hasAttr<UnusedAttr>() ||
- D->hasAttr<ObjCPreciseLifetimeAttr>())
+ if (D->hasAttr<UnusedAttr>() || D->hasAttr<ObjCPreciseLifetimeAttr>())
return false;
if (isa<LabelDecl>(D))
More information about the cfe-commits
mailing list