[clang] [clang] Improve the lifetime_capture_by diagnostic on the constructor. (PR #117792)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 19:57:41 PST 2024


================
@@ -411,3 +411,22 @@ void use() {
 }
 } // namespace with_span
 } // namespace inferred_capture_by
+
+namespace on_constructor {
+struct T {
+  T(const int& t [[clang::lifetime_capture_by(this)]]);
+};
+struct T2 {
+  T2(const int& t [[clang::lifetime_capture_by(x)]], int& x);
+};
+int foo(const T& t);
----------------
usx95 wrote:

could you also add
```cpp
int bar(const T& t[[clang::lifetimebound]]);
auto y = bar(T(1));
```
```cpp
struct T3 {
T3(const T& t [[clang::lifetime_capture_by(this));
};
T3 t3(T(1));
```

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


More information about the cfe-commits mailing list