<div dir="ltr">This is the approach I've always wanted ever since I experienced YAMLIO's Hex* classes. I can never remember the right printf format specifiers for width and stuff (not to mention the iostream manipulators), and the PRI* macros are ugly and error-prone.<div><br></div><div>Also you're not the only one running into these issues: llvm::format, such as r185766 and PR20715. I also seem to remember one more, but I can't find it.</div><div><br></div><div>The argument could be made that we should improve clang's printf checking to handle things like the snprintf in the function template like what llvm::format uses, but I think that's orthogonal.</div><div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 17, 2014 at 7:34 PM, <a href="mailto:kledzik@apple.com">kledzik@apple.com</a> <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rafael, silvas,<br>
<br>
In using llvm::format() to dump columnar tables of data in my recent enhancements to llvm-objdump, I ran into some issues uncovered by the built bots that show how unsafe llvm::format() is.  The issues I hit where that the compiler did not check that %x match the integer size and that %s can match a StringRef but produce the wrong output.  %s is also ugly with StringRef values because you have to convert to a std::string then call c_str().<br>
<br>
All I really needed was a way to generate fixed with hexadecimal (e.g. 0x00001234) and fixed with strings (e.g. right or left justified strings in a column).  I whipped up an alternative that is easy to use with the stream operator and generates fixed with output.<br>
<br>
If there is interest in this, I can clean it up and add some test cases.  Or perhaps there already is some good technique for fixed width formatting.  This patch also contains examples changes in llvm-objdump to use this new functionality.<br>
<br>
<a href="http://reviews.llvm.org/D5390" target="_blank">http://reviews.llvm.org/D5390</a><br>
<br>
Files:<br>
  include/llvm/Support/Format.h<br>
  include/llvm/Support/raw_ostream.h<br>
  lib/Support/raw_ostream.cpp<br>
  tools/llvm-objdump/MachODump.cpp<br>
</blockquote></div><br></div>