<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63787>63787</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy readability-make-member-function-const suggests a change that breaks runtime behavior
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
stingray-11
</td>
</tr>
</table>
<pre>
I have the following code. There is a generic template function, and a specialized version to handle nullptr_t. The generic one modifies the object that it's part of (non-const), while the specialized version does not. clang-tidy thus produces a "readability-make-member-function-const" warning suggesting to add const to the end of the nullptr_t version.
This seems right, but it breaks runtime behavior. At runtime, calling Equals(nullptr_t) will result in the generic version being selected rather than the nullptr_t specialized version. I'm not _entirely_ sure that this isn't a compiler bug, but both GCC and Clang behave this way.
I'm running Ubuntu 23.04 with GCC 12.2, and clang/clang-tidy 15.0.7
```
template<typename T>
[[nodiscard]] std::string Equals(const std::string& key, const T& val)
{
return key+" = "+AddParam(val);
}
[[nodiscard]] std::string Equals(const std::string& key, std::nullptr_t val)
{
return IsNull(key);
}
```
Right now the only way to solve this is to add `// NOLINT(*-make-member-function-const)` after the nullptr_t function.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM1u6zYTfRpqM7AgUZYlLbRw4usPAT6kRZGuA0ocS2wo0iWHMdynLyhZuc5FbtFFDUO2-DNzzpkzI7xXg0FsWfnAykMiAo3WtZ6UGZy4bvI86ay8tk8wincEGhFOVmt7UWaA3kpMAV5GdAjKg4ABDTrVA-F01oIQTsH0pKxh_BGEkSDAn7FXQqu_UMI7Oq-sAbIwCiM1gglan8m90hL3I6A1CJOV6qTQzyhs9wf2BDQKAkWMVx7OwhHYEzBeG2s2vTWeGG9i6suo9IL-q_TSogdjY85eCzNsSMkr0Bg8nJ2VocfIjXHuUEjRKa3oupnEG24mnDp0m5XlmpPDRTgTJfJhGHBWM5IUUsJ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