[PATCH] D18703: [clang-tidy] Add new checker for comparison with runtime string functions.
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 1 11:51:48 PDT 2016
etienneb added a comment.
As pointed by Eugene,
The following code seems to produce multiple errors.
int foo() {
if (strcmp(A, "a") == true)
return 0;
return 1;
}
Results:
/home/etienneb/examples/test.cc:56:7: warning: function 'strcmp' is compared to a suspicious constant [misc-suspicious-string-compare]
if (strcmp(A, "a") == true)
^
/home/etienneb/examples/test.cc:56:25: warning: implicit cast bool -> 'int' [readability-implicit-bool-cast]
if (strcmp(A, "a") == true)
^
/home/etienneb/examples/test.cc:56:25: warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]
if (strcmp(A, "a") == true)
^
static_cast<bool>(strcmp(A, "a"))
On my side, I'm not against to keep it that way.
The //implicit cast bool -> 'int'// warning is often too noisy and is often ignored by programmers.
The other message sounds more specific and may ring a bell.
WDYT?
http://reviews.llvm.org/D18703
More information about the cfe-commits
mailing list