================
@@ -1784,3 +1784,141 @@ void test_optional_view_arrow() {
(void)*p;
}
} // namespace OwnerArrowOperator
+
----------------
usx95 wrote:
I think we also needs invalidation tests similar to @Xazax-hun suggestions:
```cpp
// Captured view invalidated by modifying the owner
string s = "42";
string_view p = s;
auto lambda = [=] { return p; };
s.push_back('c'); // invalidates p
lambda(); // should warn: use-after-invalidate
// Multiple captures, only one invalidated
string s1 = "a", s2 = "b";
string_view p1 = s1, p2 = s2;
auto lambda = [=] { return p1.size() + p2.size(); };
s1.clear(); // invalidates p1 but not p2
lambda(); // should warn about p1, not p2
// Capture by reference, owner invalidated
string s = "42";
string_view p = s;
auto lambda = [&] { return p; };
s.push_back('c'); // invalidates p
lambda(); // should warn: use-after-invalidate
string s = "42", safe = "not modified";
string_view p = s;
auto lambda = [&] { return p; };
p = safe; // p now points to 'safe', not 's'
s.push_back('c'); // does not invalidate p anymore
lambda(); // should not warn (FIXME: merged origins can't track this, also
needs to track pointer-indirections)
```
https://github.com/llvm/llvm-project/pull/185216
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits