Skip to content

Commit

Permalink
[clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-paramete…
Browse files Browse the repository at this point in the history
…r StrCat().

Differential Revision: https://reviews.llvm.org/D91601
  • Loading branch information
hokein committed Nov 17, 2020
1 parent 3a5c0ea commit af0d607
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Expand Up @@ -47,6 +47,8 @@ struct StrCatCheckResult {
};

void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) {
if (Call->getNumArgs() == 0)
return;
// Remove 'Foo('
CheckResult->Hints.push_back(
FixItHint::CreateRemoval(CharSourceRange::getCharRange(
Expand Down
Expand Up @@ -121,6 +121,7 @@ struct AlphaNum {
AlphaNum &operator=(const AlphaNum &);
};

string StrCat();
string StrCat(const AlphaNum &A);
string StrCat(const AlphaNum &A, const AlphaNum &B);
string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C);
Expand Down Expand Up @@ -182,6 +183,9 @@ void Positives() {
StrAppend(&S, StrCat(1, 2, 3, 4, 5), StrCat(6, 7, 8, 9, 10));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
// CHECK-FIXES: StrAppend(&S, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

StrCat(1, StrCat());
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
}

void Negatives() {
Expand Down

0 comments on commit af0d607

Please sign in to comment.