https://bugs.llvm.org/show_bug.cgi?id=42614
Bug ID: 42614
Summary: [clang or clang-tidy] -Wformat awareness for
<cinttypes>
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected]
printf()-style functions have a well-defined format string:
https://en.cppreference.com/w/cpp/io/c/fprintf
clang knows how to verify it (-Wformat),
However there is a huge pitfall hiding in plain sight.
If one defines the variable e.g. as uint64_t: normally it is a 'unsigned long',
so one will just use %lu - that is what clang recommends.
But on different platform uint64_t can be 'unsigned long long',
and -Wformat will complain that '%llu' should be used.
Neither of these is the "correct" solution - PRIu64 should be used instead.
https://en.cppreference.com/w/cpp/header/cinttypes
Now, obviously the current -Wformat behavior isn't wrong - it does produce
the correct results on the current platform - but they aren't *great*, since
they don't catch (and actively advertise) platform-dependent format string.
While i expect it may be reasonably trivial to distinguish whether the
printf() parameter is int or int32_t (e.g.), i'm honestly not sure how
to deal with format string parsing - the current approach won't work,
as it would need to be done before macro substitution.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs