This revision was automatically updated to reflect the committed changes. Closed by commit rGaf0d607e7275: [clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-parameter StrCat(). (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91601/new/ https://reviews.llvm.org/D91601 Files: clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp Index: clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp +++ clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp @@ -121,6 +121,7 @@ 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 @@ 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() { Index: clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp +++ clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp @@ -47,6 +47,8 @@ }; void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) { + if (Call->getNumArgs() == 0) + return; // Remove 'Foo(' CheckResult->Hints.push_back( FixItHint::CreateRemoval(CharSourceRange::getCharRange(
Index: clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp +++ clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp @@ -121,6 +121,7 @@ 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 @@ 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() { Index: clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp +++ clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp @@ -47,6 +47,8 @@ }; void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) { + if (Call->getNumArgs() == 0) + return; // Remove 'Foo(' CheckResult->Hints.push_back( FixItHint::CreateRemoval(CharSourceRange::getCharRange(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits