<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140483>140483</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] `-Wdangling` does not emit warning when a dangerous call invoked in STL
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
Please be patient reading all examples below - root of the evil hidden in the fact that `std::pair<const A, B>` not the same as `std::pair<A, B>` but the first one might be implicitly converted to the second one. Such implicit conversion might lead to hidden UB if not carefully coded.
Assume we have a `proj` lambda like this:
```
const auto proj =
[](const std::pair<std::string, int>& node [[clang::lifetimebound]])
-> const std::pair<std::string, int>& {
return node;
};
```
Let's call this lambda directly by creating the problem with dangling reference artifically:
```
std::pair<const std::string, int> aa;
const auto& a = proj(aa);
```
Then we will watch `warning: temporary bound to local reference 'a' will be destroyed at the end of the full-expression [-Wdangling]` emited - that's fine.
Now let's create conditions under which the function will be called outside of user code, but the problem with the dangling reference will still be relevant:
```
std::map<std::string, int> counters = { {"hello", 5}, {"world", 5} };
for (const auto& node : counters | std::views::transform(proj)) {
(void)node; // dangling
}
```
And here we will not see that warning emited - that's the problem that I am creating this issue about and which should be fixed.
The full snippet here: https://godbolt.org/z/1Yaj1s6Wf
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVc1u2zgQfhr6MnAgU_LfwQc5aYAFisUC7aLY44gcWWwpUiApu-7TL4ZSHLdJ97BCgMjicDjz_QwxRnNyRAexPor10wLH1Plw0OR--CCLYtF4fT38ZQkjQUMwYDLkEgRCbdwJ0Fqg79gPliI0ZP0FlhC8T-BbSB0BnY2FzmhNDozLn1pUCVKHCcSmiEmLshZlPaAJonxU3sUEtZCPcBTlB7EpwPmU90XsCTC-t-un-Gac4lsTYgLvCHpz6hKXb_rBGmWSvYLy7kwhkYbkp_SkvNMc_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