<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117696>117696</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] bugprone-return-const-ref-from-parameter should ignore [[clang::lifetimebound]] parameters
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RedBeard0531
</td>
</tr>
</table>
<pre>
[godbolt](https://godbolt.org/z/fz7sbPfqe)
```cpp
template <typename T>
const T& max(const T& a [[clang::lifetimebound]], const T& b [[clang::lifetimebound]]) {
return a > b ? a : b; // trips bugprone-return-const-ref-from-parameter
}
int add_one(const int& x) { return x + 1; }
void test() {
int fine = max(1, 2);
int also_fine = add_one(max(1, 2));
const int& bad = max(1,2); // trips -Wdangling
}
```
`[[clang::lifetimebound]]` indicates that it is intentional to return a reference from an argument, so clang tidy warning about it is just telling the author what they already know. Also, the attribute enables clang to give more precise warnings when the function is _used_ in a bad way, rather than just preemptively warning in the definition even when used correctly.
Ideally, this should even suggest a fixit to add the attribute so that we can get the precise warnings while still taking advantage of the performance benefits of not copying for non-trivial arguments.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVEFvqzoT_TXOZkQEppBkwSJpbqRv9-npSm9ZDXgA32tsnj0kzf31T4akSau3qITUBvvMOXPOMBiC7ixRJYqDKI4rnLh3vvqL1IHQq7TIs1Xt1DWed07VzrAojkJue-YxiHwv5EnI0-1o7Xwn5OmPkKf2zybU_2__ISF3It3Hp0yXpxlHke6ZhtEgE4j8la8jWRwIfor8h0j3jbOB4aeQJQz4LuT26QXCLPXQGLRdFJDvjW6J9UC1m6yK8qLCV3gC1d8E7UBsDiLdAwB44snbyJf_iAXy0_z_HmqRH2DpG9jrMUA9daN3lpIFk8zMiac2ab0bkhE9DsTkowub42KHtgyo1Juz9NGgthzVvt-E3CW8g5A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