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(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() || - D->hasAttr()) + if (D->hasAttr() || D->hasAttr()) return false; if (isa(D))