[clang-tools-extra] af0d607 - [clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-parameter StrCat().
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 17 02:12:14 PST 2020
Author: Haojian Wu
Date: 2020-11-17T11:05:24+01:00
New Revision: af0d607e727512775e8dbec1baf7bfa15c7ecb48
URL: https://github.com/llvm/llvm-project/commit/af0d607e727512775e8dbec1baf7bfa15c7ecb48
DIFF: https://github.com/llvm/llvm-project/commit/af0d607e727512775e8dbec1baf7bfa15c7ecb48.diff
LOG: [clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-parameter StrCat().
Differential Revision: https://reviews.llvm.org/D91601
Added:
Modified:
clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
index e7d037743f678..be3fa9a5628b4 100644
--- a/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
@@ -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(
diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
index 3afbac505cf19..dad8ef857e2a1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
@@ -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);
@@ -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() {
More information about the cfe-commits
mailing list