<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104155>104155</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Bad diagnostic for missing <inttypes.h> include for printf format specifiers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hctim
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/d8nzKfTGT
```
#include <stdio.h>
#include <stdint.h>
// #include <inttypes.h>
void x() {
uint64_t y;
printf("%" PRIux64 "]", y);
}
```
```
<source>:8:16: error: expected ')'
8 | printf("%" PRIux64 "]", y);
| ^
<source>:8:11: note: to match this '('
8 | printf("%" PRIux64 "]", y);
| ^
1 error generated.
Compiler returned: 1
```
This was a real head-scratcher for me. Even an LLM couldn't figure it out. Sometimes GCC can provide better diagnostics here, but not always (the above printf example is roughly the same diagnostics on gcc, but sscanf provides better):
https://godbolt.org/z/P7z3e5ET8
```
#include <stdio.h>
#include <stdint.h>
#include <string>
// #include <inttypes.h>
void x() {
std::string x;
uint64_t y;
if (sscanf(x.c_str() + 1, "%" SCNx64 "]", &y) != 1) return;
}
```
```
<source>: In function 'void x()':
<source>:9:34: error: expected ')' before 'SCNx64'
9 | if (sscanf(x.c_str() + 1, "%" SCNx64 "]", &y) != 1) return;
| ~ ^~~~~~~
| )
<source>:4:1: note: 'SCNx64' is defined in header '<cinttypes>'; this is probably fixable by adding '#include <cinttypes>'
3 | #include <string>
+++ |+#include <cinttypes>
4 | // #include <inttypes.h>
Compiler returned: 1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk2P2zYQ_TX0ZbCGROrLBx283nUQNC2CZu8BRY4kFhJpkJTX3kN-e0FJ64_9SNogLWFI8pAcvXmc9yDunGo0YknSW5LeLfjgW2PLVnjVLyojj2Xr_c4RtiZ0S-i2MbIynV8a2xC6fSJ0Kw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