| Issue |
63787
|
| Summary |
clang-tidy readability-make-member-function-const suggests a change that breaks runtime behavior
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
stingray-11
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs