@@ -202,12 +202,12 @@ UseStructuredBindingCheck::UseStructuredBindingCheck(StringRef Name,
202
202
;
203
203
}
204
204
205
- static auto getVarInitWithMemberMatcher (StringRef PairName,
206
- StringRef MemberName ,
207
- StringRef TypeName ,
208
- StringRef BindingName ) {
205
+ static auto getVarInitWithMemberMatcher (
206
+ StringRef PairName, StringRef MemberName, StringRef TypeName ,
207
+ StringRef BindingName ,
208
+ ast_matchers::internal::Matcher<VarDecl> ExtraMatcher ) {
209
209
return varDecl (
210
- unless ( hasAnySpecifiersShouldBeIgnored ()), unless ( isInMarco ()) ,
210
+ ExtraMatcher ,
211
211
hasInitializer (
212
212
ignoringImpCasts (ignoringCopyCtorAndImplicitCast (memberExpr (
213
213
hasObjectExpression (ignoringImpCasts (declRefExpr (
@@ -223,10 +223,20 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
223
223
hasUnqualifiedDesugaredType (recordType (
224
224
hasDeclaration (cxxRecordDecl (hasAnyName (PairTypes))))));
225
225
226
- auto VarInitWithFirstMember = getVarInitWithMemberMatcher (
227
- PairDeclName, " first" , FirstTypeName, FirstVarDeclName);
228
- auto VarInitWithSecondMember = getVarInitWithMemberMatcher (
229
- PairDeclName, " second" , SecondTypeName, SecondVarDeclName);
226
+ auto UnlessShouldBeIgnored =
227
+ unless (anyOf (hasAnySpecifiersShouldBeIgnored (), isInMarco ()));
228
+
229
+ auto VarInitWithFirstMember =
230
+ getVarInitWithMemberMatcher (PairDeclName, " first" , FirstTypeName,
231
+ FirstVarDeclName, UnlessShouldBeIgnored);
232
+ auto VarInitWithSecondMember =
233
+ getVarInitWithMemberMatcher (PairDeclName, " second" , SecondTypeName,
234
+ SecondVarDeclName, UnlessShouldBeIgnored);
235
+
236
+ auto RefToBindName = [&UnlessShouldBeIgnored](const llvm::StringLiteral &Name)
237
+ -> ast_matchers::internal::BindableMatcher<Stmt> {
238
+ return declRefExpr (to (varDecl (UnlessShouldBeIgnored).bind (Name)));
239
+ };
230
240
231
241
// X x;
232
242
// Y y;
@@ -237,23 +247,10 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
237
247
has (cxxOperatorCallExpr (
238
248
hasOverloadedOperatorName (" =" ),
239
249
hasLHS (ignoringImplicit (
240
- callExpr (
241
- callee (
242
- functionDecl (isInStdNamespace (), hasName (" tie" ))),
243
- hasArgument (
244
- 0 ,
245
- declRefExpr (to (
246
- varDecl (
247
- unless (hasAnySpecifiersShouldBeIgnored ()),
248
- unless (isInMarco ()))
249
- .bind (FirstVarDeclName)))),
250
- hasArgument (
251
- 1 ,
252
- declRefExpr (to (
253
- varDecl (
254
- unless (hasAnySpecifiersShouldBeIgnored ()),
255
- unless (isInMarco ()))
256
- .bind (SecondVarDeclName)))))
250
+ callExpr (callee (functionDecl (isInStdNamespace (),
251
+ hasName (" tie" ))),
252
+ hasArgument (0 , RefToBindName (FirstVarDeclName)),
253
+ hasArgument (1 , RefToBindName (SecondVarDeclName)))
257
254
.bind (StdTieExprName))),
258
255
hasRHS (expr (hasType (PairType))))
259
256
.bind (StdTieAssignStmtName)),
@@ -269,7 +266,7 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
269
266
declStmt (
270
267
unless (isInMarco ()),
271
268
hasSingleDecl (
272
- varDecl (unless ( hasAnySpecifiersShouldBeIgnored ()) ,
269
+ varDecl (UnlessShouldBeIgnored ,
273
270
hasType (qualType (anyOf (PairType, lValueReferenceType (
274
271
pointee (PairType))))
275
272
.bind (PairVarTypeName)),
0 commit comments