Skip to content

Commit

Permalink
[clang-tidy] Make readability-string-compare check use <string> header
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mikecrowe authored and PiotrZSL committed Mar 12, 2023
1 parent b53ea2b commit f9dc14c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -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_
@@ -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);

Expand Down

0 comments on commit f9dc14c

Please sign in to comment.