[PATCH] D131057: [Sema] -Wformat: support C23 format specifier %b %B

Elliott Hughes via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 4 10:29:30 PDT 2022


enh added a comment.

In D131057#3697392 <https://reviews.llvm.org/D131057#3697392>, @MaskRay wrote:

> In D131057#3697095 <https://reviews.llvm.org/D131057#3697095>, @dim wrote:
>
>>> GCC 12 -Wformat -pedantic emits a warning:
>>>
>>>   warning: ISO C17 does not support the ‘%b’ gnu_printf format [-Wformat=]
>>>
>>> The behavior is not ported (and it's unclear to me how to implement it).
>>
>> If you really want this, I think it can be implemented by looking at `LangOpts::LangStd`.
>
> Something like `!getLangOpts().C2X` I suppose, but I do not find how to check both `-Wformat` and `-Wpedantic`.
> Also, for the nature of the diagnostic, I think something in TableGen like `def ext_... InGroup<C2x>` would make sense but using a C23/C2x related -W option would deviate from the GCC behavior.
> ISTM adding the diagnostic (even if we do) is not so necessary in this patch.

note that that's not even what we'd want for Android anyway ... availability and behavior on Android is always[1] predicated on the API level, not the C standard. app developers can't avoid dealing with the API level, so we've avoided having an orthogonal versioning concern for them. (this is true in the headers too, not just behavior: on Android you always get the API-level-appropriate _library_ no matter what version of the language you select.)

and, like i said elsewhere, no-one's ever noticed that clang just assumes `%m` is always available. even though _i've_ wanted %b since i was a kid[2], i'm not actually expecting %b will be heavily used in practice. (tbh, i doubt %b will ever be used in `scanf()` outside of tests. as far as i'm concerned only the `printf()` side is actually useful...)

____

1. the removal of `gets()` is the only exception that springs to mind.
2. even though i know that for weird-ass machines like the PDP series, octal was more useful than it is to the rest of us, i still can't believe %b wasn't in B, let alone C!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131057



More information about the cfe-commits mailing list