================
@@ -582,6 +582,15 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
     //   Temp().ptr; // Here ptr might not dangle.
     if (isa<MemberExpr>(Arg->IgnoreImpCasts()))
       return;
+    // Avoid false positives when the object is constructed from a conditional
+    // operator argument. A common case is:
+    //   // 'ptr' might not be owned by the Owner object.
+    //   std::string_view s = cond() ? Owner().ptr : sv;
----------------
hokein wrote:

> I am wondering if it was possible to use the same or similar MemberExpr 
> filter when we drill down to the branches of the conditional operator. If it 
> is too hard to do, 

This was my first approach. We could add a special `MemberExpr` filter inside 
the `do-while` loop in `visitLocalsRetainedByReferenceBinding`, but I don’t 
think it’s a good idea:

- the filtering logic is GSL-pointer specific, and 
`visitLocalsRetainedByReferenceBinding` shouldn’t be aware of it;  (layering 
violation)
- adding such filtering causes new false negatives in cases like `const 
string_view& sv = Owner().sv;`.  
- it would scatter the special filtering logic into another place, making the 
code harder to reason about.



https://github.com/llvm/llvm-project/pull/120233
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to