[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy
Malcolm Parsons via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 29 12:31:01 PST 2016
malcolm.parsons added a comment.
Please run clang-format on all new files.
================
Comment at: test/clang-tidy/misc-string-compare.cpp:3
+
+#include <string>
+
----------------
clang-tidy tests don't #include system headers.
Declare the bits you need instead.
See test/clang-tidy/misc-string-constructor.cpp for an example.
================
Comment at: test/clang-tidy/misc-string-compare.cpp:9
+
+ if(str1.compare(str2)) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
----------------
Some other test ideas:
```
if (str1.compare("foo")) {}
return str1.compare(str2) == 0;
func(str1.compare(str2) != 0);
if (str2.empty() || str1.compare(str2) != 0) {}
```
https://reviews.llvm.org/D27210
More information about the cfe-commits
mailing list