@@ -2005,12 +2005,12 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts,
2005
2005
if (D->isInvalidDecl())
2006
2006
return false;
2007
2007
2008
- if (auto *DD = dyn_cast<DecompositionDecl>(D)) {
2008
+ if (const auto *DD = dyn_cast<DecompositionDecl>(D)) {
2009
2009
// For a decomposition declaration, warn if none of the bindings are
2010
2010
// referenced, instead of if the variable itself is referenced (which
2011
2011
// it is, by the bindings' expressions).
2012
2012
bool IsAllPlaceholders = true;
2013
- for (auto *BD : DD->bindings()) {
2013
+ for (const auto *BD : DD->bindings()) {
2014
2014
if (BD->isReferenced())
2015
2015
return false;
2016
2016
IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
@@ -2054,7 +2054,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts,
2054
2054
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2055
2055
2056
2056
const Expr *Init = VD->getInit();
2057
- if (const auto *Cleanups = dyn_cast_or_null <ExprWithCleanups>(Init))
2057
+ if (const auto *Cleanups = dyn_cast_if_present <ExprWithCleanups>(Init))
2058
2058
Init = Cleanups->getSubExpr();
2059
2059
2060
2060
const auto *Ty = VD->getType().getTypePtr();
@@ -2068,11 +2068,10 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts,
2068
2068
2069
2069
// Warn for reference variables whose initializtion performs lifetime
2070
2070
// extension.
2071
- if (const auto *MTE = dyn_cast_or_null<MaterializeTemporaryExpr>(Init)) {
2072
- if (MTE->getExtendingDecl()) {
2073
- Ty = VD->getType().getNonReferenceType().getTypePtr();
2074
- Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2075
- }
2071
+ if (const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(Init);
2072
+ MTE && MTE->getExtendingDecl()) {
2073
+ Ty = VD->getType().getNonReferenceType().getTypePtr();
2074
+ Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2076
2075
}
2077
2076
2078
2077
// If we failed to complete the type for some reason, or if the type is
@@ -2089,15 +2088,14 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts,
2089
2088
if (Tag->hasAttr<UnusedAttr>())
2090
2089
return false;
2091
2090
2092
- if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2091
+ if (const auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2093
2092
if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2094
2093
return false;
2095
2094
2096
2095
if (Init) {
2097
- const CXXConstructExpr *Construct =
2098
- dyn_cast<CXXConstructExpr>(Init);
2096
+ const auto *Construct = dyn_cast<CXXConstructExpr>(Init);
2099
2097
if (Construct && !Construct->isElidable()) {
2100
- CXXConstructorDecl *CD = Construct->getConstructor();
2098
+ const CXXConstructorDecl *CD = Construct->getConstructor();
2101
2099
if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2102
2100
(VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2103
2101
return false;
0 commit comments