Issue |
146429
|
Summary |
[Clang] -Wformat size_t issues: suggests `%zf` for "broken" namespaced size_t, doesn't recognize `sizeof(...)`
|
Labels |
clang
|
Assignees |
|
Reporter |
rprichard
|
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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs