aaron.ballman added a comment. In D66856#1649721 <https://reviews.llvm.org/D66856#1649721>, @erik.pilkington wrote:
> In D66856#1648809 <https://reviews.llvm.org/D66856#1648809>, @aaron.ballman > wrote: > > > I'm wondering whether this should even warn pedantically. There are no > > format specifiers that apply directly to a `_Bool` datatype, so the user is > > left making a choice as to what specifier fits best. I think `hhd` and > > `hhu` are both equally reasonable types, as are the `d` and `u` groups > > directly -- I don't think we should warn on either of those specifiers with > > a `_Bool` argument. I could maybe see a case for pedantically diagnosing > > `h`, `l`, and `ll` prefixes with `_Bool` because that seems a bit > > type-confused to me. `c` as a specifier seems weird (given that false > > values will potentially terminate the string suddenly depending on terminal > > behavior, IIRC), but `lc` seems like type confusion again. > > > Hmm... on second though I think the `l` and `ll` prefixes are worth -Wformat > proper, since that can result in printing a half-initialized integer when the > argument ends up on the stack (we generate `movl $0,(%rsp)` for the first > stack argument). Agreed. > I think `%c` is probably also worth a -Wformat, it seems like it would almost > certainly be a mistake. That's my feeling as well. At the very least, -Wformat-pedantic. > I suppose we could pedantically warn on `%hd`, but I'm not sure. I think it makes sense to dos o. > Who is the audience for -Wformat-pedantic? To me, the audience are people who want to catch semantically-benign-but-logically-inconsistent format strings. e.g., it's not wrong to pass 'c' to something formatted as `%hd`, but it smells fishy to do so. > Users that expect it to diagnose any pedantically-UB printf calls will > already be disappointed, since the C standard seems to be quite a lot more > restrictive then us (7.21.6.9p9 says: "If any argument is not the correct > type for the corresponding conversion specification, the behavior is > undefined." (I'm assuming "correct type" means "same type")). So I think we > should just concern ourselves with calls that would lead to actual problems > at runtime, or are likely programmer errors, and `printf("%hd", (_Bool)0)` > doesn't seem to meet either of those bars. To me, actual problems at runtime belong in -Wformat and logical inconsistencies that don't cause runtime problems belong in -Wformat-pedantic. However, I think it's a defect that the C standard has no clearly UB-free way to print a _Bool value. I will bring this up on the reflectors to ask if we can clarify the standard here. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66856/new/ https://reviews.llvm.org/D66856 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits