[PATCH] D112579: Allow non-variadic functions to be attributed with `__attribute__((format))`
FĂ©lix Cloutier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 29 17:25:50 PDT 2021
fcloutier added a comment.
Thanks Arthur for your feedback.
void myprintf(const char *fmt, int n) __attribute__((format(printf, 1, 2))); // N.B.: int, not unsigned long
int main() {
myprintf("%lu", 3uL); // this should error
myprintf("%d", 3uL); // this should not error
}
This is handled naturally by the current implementation. The integer literal undergoes an implicit cast to `int` because that's the type of the `n` parameter, and it causes the %lu case to fail and the %d case to succeed.
Your second example is the scenario of concern for adding an attribute like the `format_like` attribute that I described in my response to Aaron. I think that these two features don't need to be tied together.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112579/new/
https://reviews.llvm.org/D112579
More information about the cfe-commits
mailing list