@@ -55,6 +55,7 @@ static bool matchNVarDeclStartingWith(
55
55
BeginDS = EndDS;
56
56
57
57
auto Matches = [&](const Decl *VD) {
58
+ // We don't want redundant decls in DeclStmt.
58
59
if (Count == N)
59
60
return false ;
60
61
@@ -113,7 +114,7 @@ AST_MATCHER_P(Stmt, hasPreTwoVarDecl,
113
114
if (Parents.size () != 1 )
114
115
return false ;
115
116
116
- auto *C = Parents[0 ].get <CompoundStmt>();
117
+ const auto *C = Parents[0 ].get <CompoundStmt>();
117
118
if (!C)
118
119
return false ;
119
120
@@ -128,12 +129,11 @@ AST_MATCHER_P(Stmt, hasPreTwoVarDecl,
128
129
AST_MATCHER_P (Stmt, hasNextTwoVarDecl,
129
130
llvm::SmallVector<ast_matchers::internal::Matcher<VarDecl>>,
130
131
InnerMatchers) {
131
-
132
132
const DynTypedNodeList Parents = Finder->getASTContext ().getParents (Node);
133
133
if (Parents.size () != 1 )
134
134
return false ;
135
135
136
- auto *C = Parents[0 ].get <CompoundStmt>();
136
+ const auto *C = Parents[0 ].get <CompoundStmt>();
137
137
if (!C)
138
138
return false ;
139
139
@@ -274,7 +274,8 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
274
274
hasType (qualType (anyOf (PairType, lValueReferenceType (
275
275
pointee (PairType))))
276
276
.bind (PairVarTypeName)),
277
- hasInitializer (expr (ignoringCopyCtorAndImplicitCast (expr ().bind (InitExprName)))))
277
+ hasInitializer (expr (ignoringCopyCtorAndImplicitCast (
278
+ expr ().bind (InitExprName)))))
278
279
.bind (PairDeclName)),
279
280
hasNextTwoVarDecl (
280
281
llvm::SmallVector<ast_matchers::internal::Matcher<VarDecl>>{
@@ -294,7 +295,8 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
294
295
varDecl (hasType (qualType (anyOf (PairType, lValueReferenceType (
295
296
pointee (PairType))))
296
297
.bind (PairVarTypeName)),
297
- hasInitializer (expr (ignoringCopyCtorAndImplicitCast (expr ().bind (InitExprName)))))
298
+ hasInitializer (expr (ignoringCopyCtorAndImplicitCast (
299
+ expr ().bind (InitExprName)))))
298
300
.bind (PairDeclName)),
299
301
hasBody (
300
302
compoundStmt (
@@ -376,10 +378,10 @@ void UseStructuredBindingCheck::check(const MatchFinder::MatchResult &Result) {
376
378
// Check whether PairVar, FirstVar and SecondVar have the same transfer type,
377
379
// so they can be combined to structured binding.
378
380
const auto *PairVar = Result.Nodes .getNodeAs <VarDecl>(PairDeclName);
379
- const Expr *InitE = Result.Nodes .getNodeAs <Expr>(InitExprName);
380
381
381
382
const std::optional<TransferType> PairCaptureType =
382
- getTransferType (*Result.Context , PairVar->getType (), InitE->getType ());
383
+ getTransferType (*Result.Context , PairVar->getType (),
384
+ Result.Nodes .getNodeAs <Expr>(InitExprName)->getType ());
383
385
const std::optional<TransferType> FirstVarCaptureType =
384
386
getTransferType (*Result.Context , FirstVar->getType (),
385
387
*Result.Nodes .getNodeAs <QualType>(FirstTypeName));
0 commit comments