Messages in this thread | | | From | Nick Desaulniers <> | Date | Thu, 30 Jun 2022 10:31:34 -0700 | Subject | Re: [PATCH] lib/test_printf.c: fix clang -Wformat warnings |
| |
On Thu, Jun 30, 2022 at 1:14 AM Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > > On Thu, Jun 30, 2022 at 2:11 AM Justin Stitt <justinstitt@google.com> wrote: > > > > + /* disable -Wformat for this chunk */ > > + NOWARN(-Wformat, > > test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1); > > test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1); > > test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627); > > Perhaps shift right the lines as well?
Along these lines, I think it would look nicer to pass a block statement (a group of statements) to the macro rather than use __VA_ARGS__. Here's an example: https://godbolt.org/z/fsYcGGEMb
You have to be careful with control flow out of blocks like this sometimes, but for these simple localized cases it looks like that should be fine.
As Nathan mentions, you can probably re-use the existing infra in your definition of NOWARN. I do prefer some macro to make it appear that the pragma is scoped to a block statement, rather than multiple lines for the diag push + pop inline. -- Thanks, ~Nick Desaulniers
| |