<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73270>73270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`readability-const-return-type` warning lacks context
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
#include <algorithm>
#include <map>
#include <set>
struct SelectMapKeys
{
template<class Pair>
typename Pair::first_type operator()(const Pair& p) const
{
return p.first;
}
};
void f(std::map<int, int> s)
{
std::set<int> varids;
std::transform(s.begin(), s.end(), std::inserter(varids, varids.begin()), SelectMapKeys{});
}
```
```
<source>:8:5: warning: return type 'typename pair<const int, int>::first_type' (aka 'const int') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]
8 | typename Pair::first_type operator()(const Pair& p) const
| ^
```
https://godbolt.org/z/aMMWfGvTK
In the reduced code it is obvious since there is only one usage. In the original code the struct is in a header with no indication of the actual usage which is causing this.
I also think this might be a false positive - but that needs to be handled in a different ticket.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVFGP6jYT_TXmZQQKNhB44IFlL58-Xa1UqZX6WDn2JJmuY6f2hC399ZUTYGHV3qcilISZM2fG5wzRKVHjEfdi_SLWrzM9cBvivqaIH_qMsyrYy15siulr-l4Ur6I4CKnIGzdYBKGO2jUhEredUN_-Kd_p_l8yCfkzM14Tx8Ew_IwODb_p_jte0jVfvkwPAACMXe80o1BH43RK8JOmeKcaEZceve7wmjkIdagpJv4tJyD0GDWHKORWyJ2QWxN84gkrN9ALuYMx9En41D9_IvIQPfSLkVeol0fs623o13tiup4DWaiF3Ca201ijPEfyLOQR8k19g5Sn-nLse8Go2vGKPOtINj11vwM5ap_qELvcblFhQ_524COkBXr78PNWRD5hZMzSXLnl8drlmWIsezaqfMkHlrvPM9-FuO3QoxZfg-qYwhAN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