================
@@ -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)
+ return;
+
+ // make_unique's first template argument is the type being constructed.
+ TemplateArgument TA = TAL->get(0);
+ if (TA.getKind() != TemplateArgument::Type)
+ return;
+
+ QualType T = TA.getAsType();
+ const auto *RD = T->getAsCXXRecordDecl();
+ if (!RD)
+ return;
+
+ // Find the constructor that matches make_unique's arguments.
----------------
Xazax-hun wrote:
Trying to figure out which ctor was called feels a bit error prone to me. I
wonder if it would be more reliable to try to look into the new expression
inside the body of `make_unique` and try to get the called ctor from that one.
I think iterating over the ctors here will inevitably miss a lot of things like
inherited constructors.
https://github.com/llvm/llvm-project/pull/191632
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits