[PATCH] D15636: Reduce false positives in printf/scanf format checker
Andy Gibbs via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 3 23:49:56 PST 2016
AndyG added a comment.
In your case, the first string would be highlighted only. Yes, I see what you mean. Is it possible to have multiple ranges for the diagnostic? By which I mean, to produce the following:
test.cpp:x:y: warning: data argument not used by format string [-Wformat-extra-args]
printf(condition ? "first message: %d" : "second message: %d", 5, 10);
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ ^
If so, I think the diagnostic should still track just the strings utilising the most arguments, so this would be the case with three messages, missing out the middle string since it is already using a sub-set of the arguments anyway:
test.cpp:x:y: warning: data argument not used by format string [-Wformat-extra-args]
printf(a ? "%d %d" : b ? "%d" : "%d %d", 5, 10, 20);
~~~~~ ~~~~~ ^
If you think this isn't sufficient, then my suggestion would be to make the range of the diagnostic the complete format expression, and let the programmer assess it themselves.
http://reviews.llvm.org/D15636
More information about the cfe-commits
mailing list