@@ -242,7 +242,7 @@ void UseAfterMoveFinder::getUsesAndReinits(
242
242
});
243
243
}
244
244
245
- bool isStandardSmartPointer (const ValueDecl *VD) {
245
+ bool isStandardResettableOwner (const ValueDecl *VD) {
246
246
const Type *TheType = VD->getType ().getNonReferenceType ().getTypePtrOrNull ();
247
247
if (!TheType)
248
248
return false ;
@@ -256,7 +256,8 @@ bool isStandardSmartPointer(const ValueDecl *VD) {
256
256
return false ;
257
257
258
258
StringRef Name = ID->getName ();
259
- if (Name != " unique_ptr" && Name != " shared_ptr" && Name != " weak_ptr" )
259
+ if (Name != " unique_ptr" && Name != " shared_ptr" && Name != " weak_ptr" &&
260
+ Name != " optional" && Name != " any" )
260
261
return false ;
261
262
262
263
return RecordDecl->getDeclContext ()->isStdNamespace ();
@@ -279,7 +280,7 @@ void UseAfterMoveFinder::getDeclRefs(
279
280
if (DeclRef && BlockMap->blockContainingStmt (DeclRef) == Block) {
280
281
// Ignore uses of a standard smart pointer that don't dereference the
281
282
// pointer.
282
- if (Operator || !isStandardSmartPointer (DeclRef->getDecl ())) {
283
+ if (Operator || !isStandardResettableOwner (DeclRef->getDecl ())) {
283
284
DeclRefs->insert (DeclRef);
284
285
}
285
286
}
@@ -315,9 +316,10 @@ void UseAfterMoveFinder::getReinits(
315
316
" ::std::unordered_map" , " ::std::unordered_multiset" ,
316
317
" ::std::unordered_multimap" ))))));
317
318
318
- auto StandardSmartPointerTypeMatcher = hasType (hasUnqualifiedDesugaredType (
319
- recordType (hasDeclaration (cxxRecordDecl (hasAnyName (
320
- " ::std::unique_ptr" , " ::std::shared_ptr" , " ::std::weak_ptr" ))))));
319
+ auto StandardResettableOwnerTypeMatcher = hasType (
320
+ hasUnqualifiedDesugaredType (recordType (hasDeclaration (cxxRecordDecl (
321
+ hasAnyName (" ::std::unique_ptr" , " ::std::shared_ptr" ,
322
+ " ::std::weak_ptr" , " ::std::optional" , " ::std::any" ))))));
321
323
322
324
// Matches different types of reinitialization.
323
325
auto ReinitMatcher =
@@ -340,7 +342,7 @@ void UseAfterMoveFinder::getReinits(
340
342
callee (cxxMethodDecl (hasAnyName (" clear" , " assign" )))),
341
343
// reset() on standard smart pointers.
342
344
cxxMemberCallExpr (
343
- on (expr (DeclRefMatcher, StandardSmartPointerTypeMatcher )),
345
+ on (expr (DeclRefMatcher, StandardResettableOwnerTypeMatcher )),
344
346
callee (cxxMethodDecl (hasName (" reset" )))),
345
347
// Methods that have the [[clang::reinitializes]] attribute.
346
348
cxxMemberCallExpr (
0 commit comments