@@ -28,6 +28,7 @@ static constexpr llvm::StringLiteral ScopeBlockName = "ScopeBlock";
28
28
static constexpr llvm::StringLiteral StdTieAssignStmtName = " StdTieAssign" ;
29
29
static constexpr llvm::StringLiteral StdTieExprName = " StdTieExpr" ;
30
30
static constexpr llvm::StringLiteral ForRangeStmtName = " ForRangeStmt" ;
31
+ static constexpr llvm::StringLiteral InitExprName = " init_expr" ;
31
32
32
33
// / Matches a sequence of VarDecls matching the inner matchers, starting from
33
34
// / the \p Iter to \p EndIter and set bindings for the first DeclStmt and the
@@ -273,7 +274,7 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
273
274
hasType (qualType (anyOf (PairType, lValueReferenceType (
274
275
pointee (PairType))))
275
276
.bind (PairVarTypeName)),
276
- hasInitializer (expr ()))
277
+ hasInitializer (expr (ignoringCopyCtorAndImplicitCast ( expr (). bind (InitExprName)) )))
277
278
.bind (PairDeclName)),
278
279
hasNextTwoVarDecl (
279
280
llvm::SmallVector<ast_matchers::internal::Matcher<VarDecl>>{
@@ -293,7 +294,7 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
293
294
varDecl (hasType (qualType (anyOf (PairType, lValueReferenceType (
294
295
pointee (PairType))))
295
296
.bind (PairVarTypeName)),
296
- hasInitializer (expr ()))
297
+ hasInitializer (expr (ignoringCopyCtorAndImplicitCast ( expr (). bind (InitExprName)) )))
297
298
.bind (PairDeclName)),
298
299
hasBody (
299
300
compoundStmt (
@@ -375,12 +376,7 @@ void UseStructuredBindingCheck::check(const MatchFinder::MatchResult &Result) {
375
376
// Check whether PairVar, FirstVar and SecondVar have the same transfer type,
376
377
// so they can be combined to structured binding.
377
378
const auto *PairVar = Result.Nodes .getNodeAs <VarDecl>(PairDeclName);
378
- const Expr *InitE = PairVar->getInit ();
379
- if (auto Res =
380
- match (expr (ignoringCopyCtorAndImplicitCast (expr ().bind (" init_expr" ))),
381
- *InitE, *Result.Context );
382
- !Res.empty ())
383
- InitE = Res[0 ].getNodeAs <Expr>(" init_expr" );
379
+ const Expr *InitE = Result.Nodes .getNodeAs <Expr>(InitExprName);
384
380
385
381
const std::optional<TransferType> PairCaptureType =
386
382
getTransferType (*Result.Context , PairVar->getType (), InitE->getType ());
0 commit comments