<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120388>120388</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Suggest include file for popular standard functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
clang:frontend,
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
If, e.g. write:
```c++
int main() {
std::cout << "Hello world\n";
}
```
I think it would be nice for the compiler to suggest importing `<iostream>`. If I later write
```c++
#include <iostream>
int main() {
std::cout << "Hello world\n";
int a = 0, b = 0;
std::memcpy(&a, &b, 4);
}
```
it would be nice if it suggested importing `<cstring>`. I think a simple internal list of popular functions would be enough, we don't need to get fancy here.
I don't know if this collides with functionality that clangd or similar tools already provide though.
Popular D compilers have similar functionality:
```console
~ » cat test.d
void main() {
writeln("hello world");
}
~ » ldc2 test.d
test.d(7): Error: `writeln` is not defined, perhaps `import std.stdio;` is needed?
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVMGO4ygQ_Rp8KY2FwUncBx_SyUSb20r7BRjKNjsYLCgnymW_fUXiTvd2995GQgIB9V7Vq6dSKdnBI7Zs88o2x0ItNIbYUqfQYIxFF8ytPfdMHADLoYRrtIRM7hnfsy1_LM3Ea158bz3BpKxnomHiBdguXwIkMjlE7nVYCJg8MHkAJsQf6FyAa4jOsM3BMyGYzBFsd_yIz_j-DDRa_wsswTUszkCH4K1G6EMEGhF0mGbrMAIFSMswYCKw0xwiWT9ABpEHGxJFVBOTP9mWl3Du4QxOEca1rG9rYkJar91iED5h_L56c1DGUsDkEXhWu1uP8hPkhJOeb3fCrcofmdh2ea-ZePk_-b7IZvss5SoUmi9S6UTR-uGp1Cq_gmSn2WFOFqNXDpxNBKGHOcyLUxH6xWuywad3QvRhGcac4hXBBM_EjsAjmtyrAQl65fUNRoxYPsQ4P7_98uGak6XRJtDBOWswwdXS-GRSztINaFQE2ik_GAgxp2lzOhSCS6BcRGVuMMdwsQaBxpzRSvbnmvnx6aEEo7rgE-M_RJ-tH3wKLjvnH2AHwV5fQSsCwkSlYXx_CdZ855C739zjVowfbCHE5zZ-gHZGi3fs9SCa3T1kDz9jDDEf2Ja_EWw52AQ-EBjsrUeT-zBjHNWc8r9H47O9ykTGhky9xiAaNEyePtZbmFaaF_miCmyrnaw3VSUbWYxtV9XVrttivdN8i10lq17oerPpq153Wm8L2wou6kpUDW9qyWVZVxu-4Q03teGN2e1YzXFS1pXOXaYyxKGwKS3YVoLLpimc6tCl-5gSAv2ovMYJPd0VOzAh7s1nct_H4Am9-fJgrBp8SGR1ym-bYxHbzPWjW4bEap6tnN7ZyZLD9q-3WbKOgN66x9B5M3wi5Y2K5t35xRJdOxLNKZtFnJg4DZbGpSt1mJg4ZYZ1-zHH8DdqYuJ0LzYxcVrrvbTi3wAAAP__StW6hw">