Skip to content

Commit dcb89af

Browse files
committed
feedback
1 parent 79838fc commit dcb89af

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
214214
const CXXMethodDecl *ReplacementFunction =
215215
StartsWithFunction ? StartsWithFunction : EndsWithFunction;
216216

217-
if (ComparisonExpr->getBeginLoc().isMacroID())
217+
if (ComparisonExpr->getBeginLoc().isMacroID() ||
218+
FindExpr->getBeginLoc().isMacroID())
218219
return;
219220

220221
const bool Neg = isNegativeComparison(ComparisonExpr);

clang-tools-extra/test/clang-tidy/checkers/modernize/use-starts-ends-with.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string sss,
9191
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
9292
// CHECK-FIXES: !s.starts_with("a");
9393

94-
#define STR(x) std::string(x)
95-
0 == STR(s).find("a");
96-
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
97-
// CHECK-FIXES: STR(s).starts_with("a");
98-
99-
#define STRING s
100-
if (0 == STRING.find("ala")) { /* do something */}
101-
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
102-
// CHECK-FIXES: if (STRING.starts_with("ala"))
103-
10494
#define FIND find
10595
s.FIND("a") == 0;
10696
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
@@ -265,6 +255,12 @@ void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string sss,
265255

266256
s.compare(0, 1, "ab") == 0;
267257
s.rfind(suffix, 1) == s.size() - suffix.size();
258+
259+
#define STR(x) std::string(x)
260+
0 == STR(s).find("a");
261+
262+
#define STRING s
263+
if (0 == STRING.find("ala")) { /* do something */}
268264
}
269265

270266
void test_substr() {
@@ -311,8 +307,5 @@ void test_substr() {
311307

312308
#define STR() str
313309
SUBSTR(STR(), 0, 6) == "prefix";
314-
315310
"prefix" == SUBSTR(STR(), 0, 6);
316-
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead of substr() == [modernize-use-starts-ends-with]
317-
318311
}

0 commit comments

Comments
 (0)