Skip to content

Commit 66bf4e6

Browse files
committed
[analyzer] MallocChecker: Factor out smart pointer name check
- Moved duplicate "unique_ptr"/"shared_ptr" name check into a local lambda.
1 parent 07cfed9 commit 66bf4e6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,6 +3115,10 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
31153115
static bool isSmartOwningPtrType(QualType QT) {
31163116
QT = QT->getCanonicalTypeUnqualified();
31173117

3118+
auto isSmartPtrName = [](StringRef Name) {
3119+
return Name == "unique_ptr" || Name == "shared_ptr";
3120+
};
3121+
31183122
// First try TemplateSpecializationType (for std smart pointers)
31193123
if (const auto *TST = QT->getAs<TemplateSpecializationType>()) {
31203124
const TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
@@ -3129,17 +3133,13 @@ static bool isSmartOwningPtrType(QualType QT) {
31293133
if (!isWithinStdNamespace(ND))
31303134
return false;
31313135

3132-
StringRef Name = ND->getName();
3133-
return Name == "unique_ptr" || Name == "shared_ptr";
3136+
return isSmartPtrName(ND->getName());
31343137
}
31353138

31363139
// Also try RecordType (for custom smart pointer implementations)
31373140
if (const auto *RD = QT->getAsCXXRecordDecl()) {
3138-
StringRef Name = RD->getName();
3139-
if (Name == "unique_ptr" || Name == "shared_ptr") {
3140-
// Accept any custom unique_ptr or shared_ptr implementation
3141-
return true;
3142-
}
3141+
// Accept any custom unique_ptr or shared_ptr implementation
3142+
return (isSmartPtrName(RD->getName()));
31433143
}
31443144

31453145
return false;

0 commit comments

Comments
 (0)