[PATCH] D132413: [NFC] Make format() more amenable to format attributes

Akira Hatanaka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 12:18:25 PDT 2022


ahatanak added inline comments.


================
Comment at: llvm/include/llvm/Support/Format.h:42
+public:
+  enum SpecifierType {
+    ST_EndOfFormatString,
----------------
Can you use `char` as the underlying type for enums?


================
Comment at: llvm/lib/Support/Format.cpp:328
+  PrintfStyleFormatReader EFR(Expected);
+  PrintfStyleFormatReader FFR(Fmt);
+  while (SpecifierType ST = FFR.NextSpecifier())
----------------
fcloutier wrote:
> ahatanak wrote:
> > Don't you have to check that the lengths of both lists are equal? What happens if `Expected` is `%d%d` and `Fmt` is `%d`?
> It's not UB to call `va_end` before you've read each argument of a `va_list`, so the one thing that matters is that `Fmt` doesn't have more specifiers than `Expected`. This is ensured by breaking out of the loop when `Fmt` runs out of specifiers, regardless of whether `Expected` still has more. If we run out of `Expected` specifiers while `Fmt` still has specifiers, we error out.
It's not UB, but why would a user want to pass a different number of specifiers? Isn't that an indication of some kind of error?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132413/new/

https://reviews.llvm.org/D132413



More information about the llvm-commits mailing list