[PATCH] D145312: [clang-tidy] Make readability-string-compare check use <string> header

Mike Crowe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 4 13:09:19 PST 2023


mikecrowe created this revision.
mikecrowe added a reviewer: carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Improve the generic <string> header by adding another constructor,
std::basic_string::empty and operator!= overload set so that it can be
used to replace the custom implementation in the
readability-string-compare check.


https://reviews.llvm.org/D145312

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template <typename T>
-class allocator {};
-template <typename T>
-class char_traits {};
-template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string<char> &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string<char> &str) const;
-  bool empty();
-};
-bool operator==(const basic_string<char> &lhs, const basic_string<char> &rhs);
-bool operator!=(const basic_string<char> &lhs, const basic_string<char> &rhs);
-bool operator==(const basic_string<char> &lhs, const char *&rhs);
-typedef basic_string<char> string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem %clang_tidy_headers
+#include <string>
 
 void func(bool b);
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@
   typedef basic_string<C, T, A> _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145312.502388.patch
Type: text/x-patch
Size: 2274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230304/28b2ddce/attachment.bin>


More information about the cfe-commits mailing list