[clang] [clang] Diagnose dangling issues for the "Container<GSLPointer>" case. (PR #107213)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 07:49:50 PDT 2024


================
@@ -470,10 +474,24 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
         VisitGSLPointerArg(Callee, Args[0],
                            !Callee->getReturnType()->isReferenceType());
       } else {
-        if (auto *CCE = dyn_cast<CXXConstructExpr>(Call);
-            CCE && CCE->getConstructor()->getParent()->hasAttr<PointerAttr>())
-          VisitGSLPointerArg(CCE->getConstructor()->getParamDecl(0), Args[0],
-                             true);
+        if (auto *Ctor = dyn_cast<CXXConstructExpr>(Call)) {
+          const auto *ClassD = Ctor->getConstructor()->getParent();
+          // Constructing the Container<GSLPointer> case (e.g.
+          // std::optional<string_view>) case.
+          if (const auto *CTSD =
+                  dyn_cast<ClassTemplateSpecializationDecl>(ClassD)) {
+            if (isFirstTemplateArgumentGSLPointer(CTSD->getTemplateArgs()) &&
+                CTSD->hasAttr<OwnerAttr>()) {
+              VisitGSLPointerArg(Ctor->getConstructor()->getParamDecl(0),
+                                 Args[0], true);
+              return;
----------------
usx95 wrote:

why `return` ? We don't return for ctor of GSLPointer case below. I think we might miss running lifetime bound analysis for rest of the args

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


More information about the cfe-commits mailing list