<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143509>143509</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Typo correction should be smarter about context
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
clang:frontend,
quality-of-implementation,
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AaronBallman
</td>
</tr>
</table>
<pre>
Currently, typo correction has very little intelligence about the context of the typo being corrected. As a result, we fail to suggest corrections as well as we could. For example:
This case fails to recognize we're in a context where we expect one of a handful of keywords:
```
struct S {
S() = defaul;
};
```
https://godbolt.org/z/o4snPEGve
(The same applies in many other circumstances; we should have a general mechanism that filters keywords by context.)
This case fails to recognize a type is invalid (but only in C) and suggests we replace `lock` by `long`:
```
void func() {
long x;
x = (lock);
}
```
https://godbolt.org/z/cxbjbE1bP
This case fails to recognize that only a type is valid:
```
int lang;
int main() {
(void)(ling)12;
}
```
https://godbolt.org/z/hc3rnrbKz
I expect more examples exist. The thrust of the request is to make typo correction a bit more situationally aware whenever possible.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyclM9u2zoTxZ-G2gxiSJTtSAstnKT-8OFuCrQvMKLGIhuKdMmh_-TpLyjLSW-z6b2AAJkmZnjOb3SIMZrREXVi8yQ2LwUm1j50OwzePaG1E7qi98O1e04hkGN7FfIZ-Hr0oHwIpNh4BxojnChcwRpmS2Ack7VmJKcIsPeJgTWB8o7pwuAP83Lu0pNx470XDSvYRUAIFJPlfNSZ4IDGAnuIaRwp8i8HR8AIZ7L29gblkx1WsPcB6ILT0ZKod6LMz3dtIiiMt3Yx9wuk_OjMG8GZhHwMWTfgu8qzppC3gC5HUgzeUVaOoNENh2Tz4pWuZx-GuByzLZen3EUOSTF8A_H4JModwDchGyFbEPULDHTAZEWdd8Tjy_Ljl2rNfJybyr2Q-9EPvbe88mEUcv8m5N6vo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