[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 17 05:47:11 PST 2024
================
@@ -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:
note: I keep the code simple here, and heuristic logic is not perfect and may lead to false negatives, as it filters out more cases than intended. The major case `std::string_view sv = cond ? "123" : std::string();` is still covered, I think this is a right tradeoff.
https://github.com/llvm/llvm-project/pull/120233
More information about the cfe-commits
mailing list