[clang] 7ff2f1b - [LifetimeSafety][NFC] Check names before namespaces in lifetime annotations (#246492)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 19:44:33 PST 2026


Author: Gábor Horváth
Date: 2026-11-27T03:44:27Z
New Revision: 7ff2f1bda1dde5da0e8b82735dd2d8d260fb4097

URL: https://github.com/llvm/llvm-project/commit/7ff2f1bda1dde5da0e8b82735dd2d8d260fb4097
DIFF: https://github.com/llvm/llvm-project/commit/7ff2f1bda1dde5da0e8b82735dd2d8d260fb4097.diff

LOG: [LifetimeSafety][NFC] Check names before namespaces in lifetime annotations (#246492)

Added: 
    

Modified: 
    clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp b/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
index b8b8abb0b2f98..2807a62415904 100644
--- a/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
@@ -453,8 +453,6 @@ bool isUniquePtrRelease(const CXXMethodDecl &MD) {
 
 bool isInvalidationMethod(const CXXMethodDecl &MD) {
   const CXXRecordDecl *RD = MD.getParent();
-  if (!isInStlNamespace(RD))
-    return false;
 
   // `pop_back` is excluded: it only invalidates references to the removed
   // element, not to other elements.
@@ -536,7 +534,8 @@ bool isInvalidationMethod(const CXXMethodDecl &MD) {
           .Case("unique_ptr", &UniquePtr)
           .Default(nullptr);
 
-  if (!InvalidatingMethods)
+  // Check the record name before the namespace, which walks the DeclContexts.
+  if (!InvalidatingMethods || !isInStlNamespace(RD))
     return false;
 
   // Handle Operators via OverloadedOperatorKind
@@ -564,7 +563,7 @@ bool isInvalidationMethod(const CXXMethodDecl &MD) {
 bool destructsFirstArg(const FunctionDecl &FD) {
   if (isa<CXXDestructorDecl>(FD))
     return true;
-  return isInStlNamespace(&FD) && getName(FD) == "destroy_at";
+  return getName(FD) == "destroy_at" && isInStlNamespace(&FD);
 }
 
 bool isAllocatingFunction(const FunctionDecl &FD) {
@@ -602,10 +601,11 @@ bool isFreeingFunction(const FunctionDecl &FD) {
 }
 
 bool isStdCallableWrapperType(const CXXRecordDecl *RD) {
-  if (!RD || !isInStlNamespace(RD))
+  if (!RD)
     return false;
   StringRef Name = getName(*RD);
-  return Name == "function" || Name == "move_only_function";
+  return (Name == "function" || Name == "move_only_function") &&
+         isInStlNamespace(RD);
 }
 
 bool isStdReferenceCast(const FunctionDecl *FD) {


        


More information about the cfe-commits mailing list