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

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 03:52:31 PST 2025


================
@@ -806,3 +806,31 @@ std::string_view test2(int c, std::string_view sv) {
 }
 
 } // namespace GH120206
+
+namespace GH120543 {
+struct S {
+  std::string_view sv;
+  std::string s;
+};
+struct Q {
+  const S* get() const [[clang::lifetimebound]];
+};
+void test1() {
+  std::string_view k1 = S().sv; // OK
+  std::string_view k2 = S().s; // expected-warning {{object backing the pointer will}}
+  
+  std::string_view k3 = Q().get()->sv; // OK
+  std::string_view k4  = Q().get()->s; // expected-warning {{object backing the pointer will}}
+}
----------------
usx95 wrote:

Can you add a test where this is used as an arg to a lifetimebound param.

```cpp
std::string_view foo(std::string_view sv [[clang::LB]]);
std::string_view lb1 = foo(S().s);
std::string_view lb2 = foo(Q().get()->s);
```

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


More information about the cfe-commits mailing list