<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/146429>146429</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] -Wformat size_t issues: suggests `%zf` for "broken" namespaced size_t, doesn't recognize `sizeof(...)`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rprichard
</td>
</tr>
</table>
<pre>
From https://godbolt.org/z/zssKGfhxW (reduced from https://godbolt.org/z/3G6qjb4KT):
```c++
#include <stdio.h>
namespace foo4 {
using size_t = unsigned char;
}
namespace foo5 {
using size_t = float;
}
void test_func(unsigned long s) {
// Clang suggests replacing %zu with %zu.
printf("%zu\n", foo4::size_t {});
// Clang suggests replacing %zu with %zf, a nonsensical specifier
printf("%u\n", foo5::size_t {});
// Clang suggests %lu instead of %zu.
printf("%u\n", sizeof(int));
}
```
Maybe `FormatSpecifier::namedTypeToLengthModifier` ought to ignore a type if it's in a namespace?
Alternatively, it could check whether the typedef refers to the expected integer type.
It might be nice if `sizeof(...)` was regarded as "having size_t type" for the purposes of -Wformat.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE9v27gT_TTUZRBBpv7ZBx2S-Kfih25PG6DHgiKHElua1JKUU-fTL0Zy3CAIikUBGhZMzXtv3jyPiNGMDrFj9QOrj5lY0uRDF-Zg5CSCygavLl0f_AmmlObIynvGe8b70avB25T7MDLev9Anxs-f9PTzKzC-D6gWiQr0f6ksPzX_fB-qz0-MH-i1Yj1NsR3J-AOd4p7x0jhpF4XAyseYlPH5xMr_bQVOnDDOQiJo7ytgLZUAACzRuBGiecFvCVh5hMWtTSugFlm5QrfHD1Dq36Fo60V6V332RkHCmL7pxUnG9zcq66ma8cMbyM0PeLSC7pZxxJgiBJytkETGeP2ywLNJ0_aYX-vmYFzSjO8Z5-sFqx_d-vy49k4elvevUtsHkkfOPmwi_4BaE7QA511EF40UFuKM0miD4WNR7zTVf6yJ8douYFxMKBR4_Vsr3rISl6cr4xJR3di2Yb3Ga-P_Ii4DAmuK3oeTSH_fmltlUyjU02XGJ_8XujFNX7zarpsC_DJOCZIHMzofEASky4xgNJjEeBvBOLLuNVes7DfKe5swOJHMGe2FBJsE0i-WYonyBzxPmCYMkCZcERVqCKgxRCKjX_HnjDKhAuMSjvTqZcZ8Q_9_gpMhYQOCM3LVw5riZkqe5-RIU8CzoMGPIihUIMhwPonzm7ATKuMctN_EzEuYfcRIw7j7qlfDiDVTXakO5UFk2O3aelfyXVO22dS17VBUtdCtFrLSzf5QId-3tZDtQXO555npeMHroikLzndl3eYo2-LQSllWB9RSI6sKPAljc2vPJ9ocmYlxwW5XNRU_ZFYMaOO6wziXlB_KQH3MQkcFd8MyRlYV1sQUf0Ekk-y6-NbEsfp46-a185WENtebODbF9odoitUQxvkQ_A-k1P0asroi0FiVx-gYbxMElH505gU_nkS2BNu925UmTcuQS39ivCfh16-7OfjvKBPj_VUj769enDv-bwAAAP__4iPMqQ">