[clang] [llvm] [LifetimeSafety] Add lifetimebound inference for std::make_unique (PR #191632)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 12 08:45:05 PDT 2026


================
@@ -250,6 +250,61 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
     }
     return;
   }
+
+  // Handle std::make_unique to propagate lifetimebound attributes from the
+  // constructed type's constructor to make_unique's parameters.
+  if (FD->isInStdNamespace() && FD->getDeclName().isIdentifier() &&
+      FD->getName() == "make_unique") {
+    if (!FD->isFunctionTemplateSpecialization())
+      return;
+
+    const TemplateArgumentList *TAL = FD->getTemplateSpecializationArgs();
+    if (!TAL || TAL->size() < 1)
----------------
Xazax-hun wrote:

Are there cases where we have an empty template argument list or (below) the template argument is not a type? I guess it can definitely happen with non-conforming standard libraries but I wonder if that is something we need to protect against. That being said I don't have a strong opinion here. 

https://github.com/llvm/llvm-project/pull/191632


More information about the cfe-commits mailing list