Skip to content

Commit 9883558

Browse files
mikecrowePiotrZSL
authored andcommitted
[clang-tidy][NFC] Make abseil-redundant-strcat-calls checker use <string> header
Remove duplication in abseil-redundant-strcat-calls check tests, by using dummy <string> header file string. Depends on D145310 Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D145311
1 parent f1e2469 commit 9883558

File tree

1 file changed

+22
-106
lines changed

1 file changed

+22
-106
lines changed

clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp

Lines changed: 22 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,8 @@
1-
// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t
1+
// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers
2+
#include <string>
23

34
int strlen(const char *);
45

5-
// Here we mimic the hierarchy of ::string.
6-
// We need to do so because we are matching on the fully qualified name of the
7-
// methods.
8-
struct __sso_string_base {};
9-
namespace __gnu_cxx {
10-
template <typename A, typename B, typename C, typename D = __sso_string_base>
11-
class __versa_string {
12-
public:
13-
const char *c_str() const;
14-
const char *data() const;
15-
int size() const;
16-
int capacity() const;
17-
int length() const;
18-
bool empty() const;
19-
char &operator[](int);
20-
void clear();
21-
void resize(int);
22-
int compare(const __versa_string &) const;
23-
};
24-
} // namespace __gnu_cxx
25-
26-
namespace std {
27-
template <typename T>
28-
class char_traits {};
29-
template <typename T>
30-
class allocator {};
31-
} // namespace std
32-
33-
template <typename A, typename B = std::char_traits<A>,
34-
typename C = std::allocator<A>>
35-
class basic_string : public __gnu_cxx::__versa_string<A, B, C> {
36-
public:
37-
basic_string();
38-
basic_string(const basic_string &);
39-
basic_string(const char *, C = C());
40-
basic_string(const char *, int, C = C());
41-
basic_string(const basic_string &, int, int, C = C());
42-
~basic_string();
43-
44-
basic_string &operator+=(const basic_string &);
45-
};
46-
47-
template <typename A, typename B, typename C>
48-
basic_string<A, B, C> operator+(const basic_string<A, B, C> &,
49-
const basic_string<A, B, C> &);
50-
template <typename A, typename B, typename C>
51-
basic_string<A, B, C> operator+(const basic_string<A, B, C> &, const char *);
52-
53-
typedef basic_string<char> string;
54-
55-
bool operator==(const string &, const string &);
56-
bool operator==(const string &, const char *);
57-
bool operator==(const char *, const string &);
58-
59-
bool operator!=(const string &, const string &);
60-
bool operator<(const string &, const string &);
61-
bool operator>(const string &, const string &);
62-
bool operator<=(const string &, const string &);
63-
bool operator>=(const string &, const string &);
64-
65-
namespace std {
66-
template <typename _CharT, typename _Traits = char_traits<_CharT>,
67-
typename _Alloc = allocator<_CharT>>
68-
class basic_string;
69-
70-
template <typename _CharT, typename _Traits, typename _Alloc>
71-
class basic_string {
72-
public:
73-
basic_string();
74-
basic_string(const basic_string &);
75-
basic_string(const char *, const _Alloc & = _Alloc());
76-
basic_string(const char *, int, const _Alloc & = _Alloc());
77-
basic_string(const basic_string &, int, int, const _Alloc & = _Alloc());
78-
~basic_string();
79-
80-
basic_string &operator+=(const basic_string &);
81-
82-
unsigned size() const;
83-
unsigned length() const;
84-
bool empty() const;
85-
};
86-
87-
typedef basic_string<char> string;
88-
} // namespace std
89-
906
namespace absl {
917

928
class string_view {
@@ -95,12 +11,12 @@ class string_view {
9511

9612
string_view();
9713
string_view(const char *);
98-
string_view(const string &);
14+
string_view(const std::string &);
9915
string_view(const char *, int);
10016
string_view(string_view, int);
10117

10218
template <typename A>
103-
explicit operator ::basic_string<char, traits_type, A>() const;
19+
explicit operator std::basic_string<char, traits_type, A>() const;
10420

10521
const char *data() const;
10622
int size() const;
@@ -113,36 +29,36 @@ struct AlphaNum {
11329
AlphaNum(int i);
11430
AlphaNum(double f);
11531
AlphaNum(const char *c_str);
116-
AlphaNum(const string &str);
32+
AlphaNum(const std::string &str);
11733
AlphaNum(const string_view &pc);
11834

11935
private:
12036
AlphaNum(const AlphaNum &);
12137
AlphaNum &operator=(const AlphaNum &);
12238
};
12339

124-
string StrCat();
125-
string StrCat(const AlphaNum &A);
126-
string StrCat(const AlphaNum &A, const AlphaNum &B);
127-
string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C);
128-
string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C,
129-
const AlphaNum &D);
40+
std::string StrCat();
41+
std::string StrCat(const AlphaNum &A);
42+
std::string StrCat(const AlphaNum &A, const AlphaNum &B);
43+
std::string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C);
44+
std::string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C,
45+
const AlphaNum &D);
13046

13147
// Support 5 or more arguments
13248
template <typename... AV>
133-
string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C,
49+
std::string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C,
13450
const AlphaNum &D, const AlphaNum &E, const AV &... args);
13551

136-
void StrAppend(string *Dest, const AlphaNum &A);
137-
void StrAppend(string *Dest, const AlphaNum &A, const AlphaNum &B);
138-
void StrAppend(string *Dest, const AlphaNum &A, const AlphaNum &B,
139-
const AlphaNum &C);
140-
void StrAppend(string *Dest, const AlphaNum &A, const AlphaNum &B,
141-
const AlphaNum &C, const AlphaNum &D);
52+
void StrAppend(std::string *Dest, const AlphaNum &A);
53+
void StrAppend(std::string *Dest, const AlphaNum &A, const AlphaNum &B);
54+
void StrAppend(std::string *Dest, const AlphaNum &A, const AlphaNum &B,
55+
const AlphaNum &C);
56+
void StrAppend(std::string *Dest, const AlphaNum &A, const AlphaNum &B,
57+
const AlphaNum &C, const AlphaNum &D);
14258

14359
// Support 5 or more arguments
14460
template <typename... AV>
145-
void StrAppend(string *Dest, const AlphaNum &A, const AlphaNum &B,
61+
void StrAppend(std::string *Dest, const AlphaNum &A, const AlphaNum &B,
14662
const AlphaNum &C, const AlphaNum &D, const AlphaNum &E,
14763
const AV &... args);
14864

@@ -153,8 +69,8 @@ using absl::StrAppend;
15369
using absl::StrCat;
15470

15571
void Positives() {
156-
string S = StrCat(1, StrCat("A", StrCat(1.1)));
157-
// CHECK-MESSAGES: [[@LINE-1]]:14: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
72+
std::string S = StrCat(1, StrCat("A", StrCat(1.1)));
73+
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
15874
// CHECK-FIXES: string S = StrCat(1, "A", 1.1);
15975

16076
S = StrCat(StrCat(StrCat(StrCat(StrCat(1)))));
@@ -190,7 +106,7 @@ void Positives() {
190106

191107
void Negatives() {
192108
// One arg. It is used for conversion. Ignore.
193-
string S = StrCat(1);
109+
std::string S = StrCat(1);
194110

195111
#define A_MACRO(x, y, z) StrCat(x, y, z)
196112
S = A_MACRO(1, 2, StrCat("A", "B"));

0 commit comments

Comments
 (0)