<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138486>138486</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy: modernize-use-override does not work is a parameter has `__attribute__`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</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 B {
virtual ~B() = default;
virtual void f([[maybe_unused]] int x) {}
virtual void g(int x __attribute__((unused))) {}
};
struct D : B {
~D() = default;
virtual void f([[maybe_unused]] int x) {}
virtual void g(int x __attribute__((unused))) {}
};
```
and `/tmp/compile_commands.json`:
```json
[{
"directory": "/tmp",
"command": "clang++ -std=c++11 -Werror=unused-parameter -Wsuggest-override -Wsuggest-destructor-override -c -o a.o a.cpp",
"file": "a.cpp",
"output": "a.o"
}]
```
```console
$ clang-tidy --checks=modernize-use-override --fix a.cpp
6 warnings generated.
a.cpp:8:3: warning: '~D' overrides a destructor but is not marked 'override' [clang-diagnostic-suggest-destructor-override]
8 | ~D() = default;
| ^
a.cpp:2:11: note: overridden virtual function is here
2 | virtual ~B() = default;
| ^
a.cpp:8:3: warning: annotate this function with 'override' or (rarely) 'final' [modernize-use-override]
8 | ~D() = default;
| ^
| override
a.cpp:8:8: note: FIX-IT applied suggested code changes
8 | ~D() = default;
| ^
a.cpp:9:16: warning: 'f' overrides a member function but is not marked 'override' [clang-diagnostic-suggest-override]
9 | virtual void f([[maybe_unused]] int x) {}
| ^
a.cpp:3:16: note: overridden virtual function is here
3 | virtual void f([[maybe_unused]] int x) {}
| ^
a.cpp:9:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
9 | virtual void f([[maybe_unused]] int x) {}
| ~~~~~~~ ^
| override
a.cpp:9:3: note: FIX-IT applied suggested code changes
9 | virtual void f([[maybe_unused]] int x) {}
| ^
a.cpp:9:41: note: FIX-IT applied suggested code changes
9 | virtual void f([[maybe_unused]] int x) {}
| ^
a.cpp:10:16: warning: 'g' overrides a member function but is not marked 'override' [clang-diagnostic-suggest-override]
10 | virtual void g(int x __attribute__((unused))) {}
| ^
a.cpp:4:16: note: overridden virtual function is here
4 | virtual void g(int x __attribute__((unused))) {}
| ^
a.cpp:10:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
10 | virtual void g(int x __attribute__((unused))) {}
| ~~~~~~~ ^
| override
a.cpp:10:3: note: FIX-IT applied suggested code changes
10 | virtual void g(int x __attribute__((unused))) {}
| ^
a.cpp:10:24: note: FIX-IT applied suggested code changes
10 | virtual void g(int x __attribute__((unused))) {}
| ^
clang-tidy applied 5 of 5 suggested fixes.
```
gives
```cpp
struct D : B {
~D() override = default;
void f([[maybe_unused]] int x) override {}
void g(int x override __attribute__((unused))) {}
};
```
Here, the `override` specifier for `g` is wrong, which must be
```cpp
void g(int x __attribute__((unused))) override {}
```
<https://godbolt.org/z/eG3KKPWoa>
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMmF1zmzoTxz-NfLODB4sX4wtf2KF-nk5venFmeu4yAi2gBiRGEknTi372MwJicOx03CTtOYSEsViW3_53l7BmxohSIm5JtCdRumCdrZTeonf3YJpFpvjj9rPGlmkEEvuEHmzTEnpgy7xt3UKwI36_x_6wu3V_Z6zucgt7IOs98XcA90LbjtXwY09oQugGSJACx4J1tSXBqc29EhwKZ-eY9g17zPC2k51BTqKURCkIaeFb72W9J-v0_OqS0KQ3gttbZq0WWWfx9ra_dzK6opthn5y4vz3LFEEKJNjN4viRvsj_H8J_SsYQCpP8JHm5alpR422umoZJbpZfjZIXk9mf8HcukDF-QikXGnOr9COh1InjDqNrSuiNMyOUjs4nm7xmsiR0T-gePGM5CdJ8-LhagfcFtVaaBOkQndcyzRq0qMH7YrqyRGM9dY9aC46zJY5DnpSenc3BU8CW7tdV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