Skip to content

Commit 7323c1b

Browse files
committed
[clang-tidy] Add isFriendOfClass helper function for PassByValueCheck
1 parent 50facad commit 7323c1b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ AST_MATCHER(CXXRecordDecl, isMoveConstructible) {
4444
}
4545
} // namespace
4646

47+
static bool isFriendOfClass(const CXXRecordDecl *Class,
48+
const CXXRecordDecl *Friend) {
49+
return llvm::any_of(
50+
Class->friends(), [Friend](FriendDecl *FriendDecl) -> bool {
51+
if (TypeSourceInfo *FriendTypeSource = FriendDecl->getFriendType()) {
52+
const QualType FriendType = FriendTypeSource->getType();
53+
return FriendType->getAsCXXRecordDecl() == Friend;
54+
}
55+
return false;
56+
});
57+
}
58+
4759
static TypeMatcher notTemplateSpecConstRefType() {
4860
return lValueReferenceType(
4961
pointee(unless(elaboratedType(namesType(templateSpecializationType()))),

0 commit comments

Comments
 (0)