[clang] [clang] Refine the temporay object member access filtering for GSL pointer (PR #122088)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 00:09:35 PST 2025


================
@@ -1103,6 +1094,8 @@ shouldLifetimeExtendThroughPath(const IndirectLocalPath &Path) {
   for (auto Elem : Path) {
     if (Elem.Kind == IndirectLocalPathEntry::DefaultInit)
       return PathLifetimeKind::Extend;
+    if (Elem.Kind == IndirectLocalPathEntry::MemberExpr)
+      continue;
----------------
hokein wrote:

This is necessary for the standard lifetime extension case. Since we add a new `MemberExpr` to the path, we need to skip it to maintain the existing behavior; otherwise, cases like `const int &x = A().i;` would incorrectly trigger diagnostics.

The case `const Bar& bar = foo.v.back();` is already handled on Line 1186.  

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


More information about the cfe-commits mailing list