<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [clang or clang-tidy] -Wformat awareness for <cinttypes>"
href="https://bugs.llvm.org/show_bug.cgi?id=42614">42614</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[clang or clang-tidy] -Wformat awareness for <cinttypes>
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>lebedev.ri@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>printf()-style functions have a well-defined format string:
<a href="https://en.cppreference.com/w/cpp/io/c/fprintf">https://en.cppreference.com/w/cpp/io/c/fprintf</a>
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.
<a href="https://en.cppreference.com/w/cpp/header/cinttypes">https://en.cppreference.com/w/cpp/header/cinttypes</a>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>