[clang-tools-extra] f9dc14c - [clang-tidy] Make readability-string-compare check use <string> header
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 12 06:35:06 PDT 2023
Author: Mike Crowe
Date: 2023-03-12T13:32:05Z
New Revision: f9dc14cf1f7eadffa7b11b86aaeaee5af26a21c0
URL: https://github.com/llvm/llvm-project/commit/f9dc14cf1f7eadffa7b11b86aaeaee5af26a21c0
DIFF: https://github.com/llvm/llvm-project/commit/f9dc14cf1f7eadffa7b11b86aaeaee5af26a21c0.diff
LOG: [clang-tidy] Make readability-string-compare check use <string> header
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.
Depends on D145311
Reviewed By: PiotrZSL
Differential Revision: https://reviews.llvm.org/D145312
Added:
Modified:
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
index 5cc9cd367e4d..ea9d1f9c32bf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@ struct basic_string {
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 @@ std::string 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&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
}
#endif // _STRING_
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
index 45114edf2f0b..2c08b86cf72f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ b/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);
More information about the cfe-commits
mailing list