<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54603>54603</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`clang-tidy --export-fixes` disagrees with `clang-tidy --fix` for modernize-use-default-member-init
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gburgessiv
</td>
</tr>
</table>
<pre>
On ToT, given the following source file:
```
struct Foo {
Foo(int x): y(0), x(x) {}
int x;
int y;
};
```
`clang-tidy`'s `modernize-use-default-member-init` will appropriately flag the use of `y`:
```
/usr/local/google/home/gbiv/llvm/crbug1309381/x-tidy.cc:5:7: warning: use default member initializer for 'y' [modernize-use-default-member-init]
int y;
^
= 0
/usr/local/google/home/gbiv/llvm/crbug1309381/x-tidy.cc:2:15: note: FIX-IT applied suggested code changes
Foo(int x): y(0), x(x) {}
^
/usr/local/google/home/gbiv/llvm/crbug1309381/x-tidy.cc:5:8: note: FIX-IT applied suggested code changes
int y;
^
clang-tidy applied 2 of 2 suggested fixes.
```
And `--fix` will give me the following code:
```
struct Foo {
Foo(int x): x(x) {}
int x;
int y = 0;
};
```
Which is fine. However, `clang-tidy`'s `--export-fixes` suggests a _slightly_ different fix:
```
---
MainSourceFile: '/usr/local/google/home/gbiv/llvm/crbug1309381/x.cc'
Diagnostics:
- DiagnosticName: modernize-use-default-member-init
DiagnosticMessage:
Message: 'use default member initializer for ''y'''
FilePath: '/usr/local/google/home/gbiv/llvm/crbug1309381/x.cc'
FileOffset: 57
Replacements:
- FilePath: '/usr/local/google/home/gbiv/llvm/crbug1309381/x.cc'
Offset: 27
Length: 4
ReplacementText: ''
- FilePath: '/usr/local/google/home/gbiv/llvm/crbug1309381/x.cc'
Offset: 58
Length: 0
ReplacementText: ' = 0'
Level: Warning
BuildDirectory: '/usr/local/google/home/gbiv/llvm/crbug1309381'
```
Specifically, the `Length` of the first replacement should be 5 bytes; a 4-byte replacement only removes `y(0)`, leaving a dangling comma before `x`'s init. It looks like `--fix` does the right thing because we call `cleanupAroundReplacements` after applying fixes to a source file.
We can perhaps change `modernize-use-default-member-init` to include the trailing comma (if any) in FixIts, though I wonder if it'd be better to somehow have the results of `cleanupAroundReplacements` applied to `--export-fixes` instead.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVk1v2zgQ_TX2ZSBDpqzYPviQ1GtsgHa72AZobwUljSRuadIgKX_sr98ZWbXlJE2MNtgVbEmkyMc3w5k3zGxxWHw08GAfBuIdVGqLBkKNUFqt7U6ZCrxtXE4dSuMguR3Ey0H8_X4Td7-26YNr8gAra2EwvTv2ATcHYqZMgP1AzAkBDtSO-Z0WpL4Z97czpss-OsBxUnLXbx9ObR5-er9kcurMtTRVFFRx4G9i6oGea1ugM-ofjBqPUYGlbHSI1rjO0EXKqEBjYKe0BrnZOLtxSgbUByi1rFrf0DSwJUO1sMnz7hiIVeMd3bXNpaZnZW1FPhSr2q75UWVqy5_1dk2P3GVNNU7ieTIbU3Pfsh7lOcGn9J-y53aSeJuKX5lDRx2O1IGpK6nJMEfb54DsJVdPYZDevW5yunzey9Beg_S3fpM6kiW8uZ2C_mM2FowNHGywuv8S3T_wPmiFBfimqtAHesvJIMhr2l30vxBpcHGdrHzbrZv9tEXPbcWZ5Tm4T3CC41L0UEu1Rz96IUluTcGBHEU08hT3LAMUVY-EgBn-KNivzf2fSPgu1q5O-8-1ymtQnmw3OILf7Q636DgEfiQIUYT7jXUhar3FXugc6EHCV69VVQd9-AqFKkt0SKTYWS9qYRRFx5cPUplPrYKujgIKnJe_GGAcWwTSLrBUsjLWB5X7EyWACM79f8j1ceHXVeAUZ-fZH9B7WWEPm69z7zl7xPQ6Uep0qfv1QNlDf8pQ91Df1lfnZT6WpcdwWii9GPAXbrTMcU077R_ZzZ79j2jy9YgmX08HvUdTXbABmDwe0zPpAfct4lP____GpbMrjIuvM67Tjf6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