<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149152>149152</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy: false positive readability-convert-member-functions-to-static to overloaded method
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
e-kwsm
</td>
</tr>
</table>
<pre>
Prepare `/tmp/a.cpp`:
```cpp
struct S {
void f();
void f() const;
int i = 0;
};
void S::f() { this->i++; }
void S::f() const { ; }
```
and `/tmp/compile_commands.json`:
```json
[{
"directory": "/tmp",
"command": "clang++ -c -o a.o a.cpp",
"file": "a.cpp",
"output": "a.o"
}]
```
```console
$ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 20.1.7
Optimized build.
```
```console
$ clang-tidy --checks=readability-convert-member-functions-to-static --fix a.cpp
1 warning generated.
a.cpp:9:9: warning: method 'f' can be made static [readability-convert-member-functions-to-static]
3 | void f() const;
| ~~~~~
| static
4 |
5 | int i = 0;
6 | };
7 |
8 | void S::f() { this->i++; }
9 | void S::f() const { ; }
| ^ ~~~~~
a.cpp:3:3: note: FIX-IT applied suggested code changes
3 | void f() const;
| ^
a.cpp:3:12: note: FIX-IT applied suggested code changes
3 | void f() const;
| ^
a.cpp:9:13: note: FIX-IT applied suggested code changes
9 | void S::f() const { ; }
| ^
clang-tidy applied 3 of 3 suggested fixes.
```
gives the following invalid code
```cpp
struct S {
void f();
static void f() ;
int i = 0;
};
void S::f() { this->i++; }
void S::f() { ; }
```
```console
$ clang++ -c -o a.o a.cpp
a.cpp:3:15: error: static and non-static member functions with the same parameter types cannot be overloaded
3 | static void f() ;
| ^
a.cpp:2:8: note: previous declaration is here
2 | void f();
| ^
a.cpp:9:9: error: redefinition of 'f'
9 | void S::f() { ; }
| ^
a.cpp:8:9: note: previous definition is here
8 | void S::f() { this->i++; }
| ^
2 errors generated.
```
<https://godbolt.org/z/aaYq98GMT>
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8FkuP2zbz19CXgQyJtCzroIO9u_4QIMFXIEHRngqaHNlMJFIlKW82h_72ghL9XG-a3aA1JJia9wznxZ1TW41YkXxF8vsJ7_3O2AqTL4-unWyMfKp-sdhxi0DmKaFr33aErvlUdF0AsCVJh2eejk-Ap0vnbS88fARSrEi6BNgbJaEmdEFoSdhzGAijnR8xA1JpDwoIu4c0Qov7I3rg_BiUs-VBAClW4HfKJYQ9KEJX4WErCGy3GQaNA9uJ7ujGqIdreeG2MG2nGvxDmLblWrrpZ2f0zTAMiHQZohojQCiVyqLwxj4RSglbBtBBNCX0LpARSqPwE41ouN6OHkEiIDHAp-ENoT4yBsJaNXhiuyIglJred70_pzDhY4xtfsP_060a7UyDAURnMBiUeCWfIEn2aJ0anH3__tcPQOhi530XIkLXhK6bZt9Ojd0OX-UYKICBNHICTafZtBjg_--8atU3lLDpVSOnbzNJ7FB8cYTdW-SSb1Sj_FMijN6j9UmL7QZtUvdaeGW0S7xJnOdeCUiSWn2NgU2XGTxyq5XewhY1Wu5xsGdEs2UZ3wNVOLbod0YCoUVNaAGCa9ggtFwiRBUkX73OqPFeAAAYkOIOXi6biD7-_gq_yAsRGWWOwFkAxnMeCZ6VHcwHzLH6AnFxxrgY0K8uyMBavsh6qzTP3Yjn_OHMzcO9sPiCNh7D__rdb8m7T8C7rlEowfXbLTqPEoSRCGLH9Rbdj8b4zAiSP1ypzei_pvfqbi91hzTM3ubzz97ByZizCjyoZWBqYGfaa_UV3Y2i3qo9OvA7hNo0jXkMRaf0njdqtPjtMyaW3UVc_9Mp89358r1m9kLDv8q4PNw2WmtsOERvw9jSRh_a2thc4Nhc4FH53RBtx1uEjlveokcL_qlDF7qWNj40LrNH2xguUV6l6ctRfZYc17kaSmRxnqqdxb0yvQOJouGWBxNBOdihxaiWnpL06nqv0vF5WZQX8bEosVZaDTpMfWjU_9iPfq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