<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60163>60163</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] readability-non-const-parameter: false positive in templated variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sebwolf-de
</td>
</tr>
</table>
<pre>
I find a false positive with clang-tidy's readability-non-const-parameter, if the access to the function parameter is hidden behind a template.
To reproduce:
```
#include <iostream>
constexpr size_t n = 20;
struct ForLoopRange {
static constexpr size_t start{0};
static constexpr size_t end{n};
static constexpr size_t step{1};
};
template <typename Range>
inline void fillIfThreshold(double toFill[n],
const double inQuestion[n],
double fillValue) {
constexpr double threshold = 0.001;
for (auto index = Range::start; index < Range::end; index += Range::step) {
if (inQuestion[index] > threshold) {
toFill[index] = fillValue;
}
}
}
int main() {
double toFill[n];
double inQuestion[n];
for (size_t i = 0; i < n; i++) {
toFill[i] = 0;
inQuestion[i] = 0.0001 * i;
}
const double fillValue = 12.0;
fillIfThreshold<ForLoopRange>(toFill, inQuestion, fillValue);
for (size_t i = 0; i < n; i++) {
std::cout << toFill[i] << std::endl;
}
}
```
If I run `clang-tidy test.cpp`, I get:
```
error: pointer parameter 'toFill' can be pointer to const [readability-non-const-parameter,-warnings-as-errors]
inline void fillIfThreshold(double toFill[n],
^
const
```
If I replace the for loop above with the version below, clang-tidy won't throw a false positive.
`for (size_t index = 0; index < n; index++)`
I use clang-tidy from the Fedora repositories:
```
> clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 15.0.7
Optimized build.
Default target: x86_64-redhat-linux-gnu
Host CPU: skylake
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVsuO4joTfhqzKSUyDiGwYMGl0d_S_DoXzZntyIkr4DPGjmyn6Z6nP7IJSYDu6cWgCOzUV7evirK5c_KgEVck35B8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