[PATCH] D18703: [clang-tidy] Add new checker for comparison with runtime string functions.
Eugene Zelenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 1 11:57:37 PDT 2016
Eugene.Zelenko added a comment.
In http://reviews.llvm.org/D18703#389706, @etienneb wrote:
> 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?
Actually I meant "if (strcmp(...))" statement when I refer to readability-implicit-bool-cast.
http://reviews.llvm.org/D18703
More information about the cfe-commits
mailing list