<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101980>101980</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] `[[clang::lifetimebound]]` not propagated through copies
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MitalAshok
</td>
</tr>
</table>
<pre>
This:
```c++
auto f([[clang::lifetimebound]] int& r) {
return [&]{
return r;
};
}
auto g(int i) {
return f(i);
}
struct Closure {
int& r;
int operator()() const { return r; }
};
auto F([[clang::lifetimebound]] int& r) {
return Closure{ r };
}
auto G(int i) {
return F(i);
}
```
Gets two warnings:
```
<source>:8:12: warning: address of stack memory associated with parameter 'i' returned [-Wreturn-stack-address]
8 | return f(i);
| ^
<source>:21:12: warning: address of stack memory associated with parameter 'i' returned [-Wreturn-stack-address]
21 | return F(i);
| ^
```
But if we introduce a temporary variable: https://godbolt.org/z/PEq3PKsqv
```c++
auto g(int i) {
auto l = f(i);
return l;
}
auto G(int i) {
auto l = F(i);
return l;
}
```
... There are no longer any warnings.
Trying to apply `[[clang::lifetimebound]]` to the copy constructor, like:
```c++
struct Closure {
int& r;
Closure([[clang::lifetimebound]] const Closure&) = default;
int operator()() const { return r; }
};
```
doesn't really do what is intended: The "lifetime analysis" is tied to the the temporary variable (`l`) instead of what the temporary variable was bound to (`int i`).
Lambda case is similar to the second case in #19605 (`auto f1`)
Maybe trivial copy constructors should "copy" the lifetimebound stuff too? Especially in this case as it's a NRVO variable
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVlGP4jYQ_jXmZbTI2JDAQx7YZbmH9tpTtWqfJ_GQuGfsnO0sor--cgiQ68J1rzqpUTabxJ5vZj5__giGoGtLVLDFI1tsJtjFxvnio45o1qFxnyelU8fipdGByTXjG8bP14yfzoqJx3T2b7GLDnZMLHu8x8qgrVOgXBu9o6j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