[clang-tools-extra] b751719 - [clang-tidy] Adds do-while support to performance-inefficient-string-concatenation (#186607)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 15 04:31:49 PDT 2026
Author: Berkay Sahin
Date: 2026-03-15T19:31:44+08:00
New Revision: b751719170fdba8c0b9c07b5b6a598e95baba580
URL: https://github.com/llvm/llvm-project/commit/b751719170fdba8c0b9c07b5b6a598e95baba580
DIFF: https://github.com/llvm/llvm-project/commit/b751719170fdba8c0b9c07b5b6a598e95baba580.diff
LOG: [clang-tidy] Adds do-while support to performance-inefficient-string-concatenation (#186607)
Closes #186362
---------
Co-authored-by: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Co-authored-by: EugeneZelenko <eugene.zelenko at gmail.com>
Added:
Modified:
clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst
clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
index 92e3220fdb817..1067fca289a2c 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
@@ -53,11 +53,11 @@ void InefficientStringConcatenationCheck::registerMatchers(
Finder->addMatcher(cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator)),
this);
} else {
- Finder->addMatcher(
- cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator),
- hasAncestor(stmt(anyOf(cxxForRangeStmt(),
- whileStmt(), forStmt())))),
- this);
+ Finder->addMatcher(cxxOperatorCallExpr(anyOf(AssignOperator, PlusOperator),
+ hasAncestor(stmt(anyOf(
+ cxxForRangeStmt(), whileStmt(),
+ forStmt(), doStmt())))),
+ this);
}
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 751550c2e0940..059e48b512adf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -321,6 +321,11 @@ Changes in existing checks
- Fixes false negatives when using ``std::set`` from ``libstdc++``.
+- Improved :doc:`performance-inefficient-string-concatenation
+ <clang-tidy/checks/performance/inefficient-string-concatenation>` check by
+ adding support for detecting inefficient string concatenation in ``do-while``
+ loops.
+
- Improved :doc:`performance-inefficient-vector-operation
<clang-tidy/checks/performance/inefficient-vector-operation>` check by
correctly handling vector-like classes when ``push_back``/``emplace_back`` are
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst
index 92b6b4e0370d6..56f6b9640080d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/inefficient-string-concatenation.rst
@@ -55,5 +55,5 @@ Options
.. option:: StrictMode
- When `false`, the check will only check the string usage in ``while``, ``for``
- and ``for-range`` statements. Default is `false`.
+ When `false`, the check will only warn on inefficient string usage inside loops.
+ Default is `false`.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp
index 72080ed39e59b..adc37e4c4bedf 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp
@@ -32,5 +32,11 @@ int main() {
f(mystr2 + mystr1);
mystr1 = g(mystr1);
}
+
+ do {
+ mystr1 = mystr1 + mystr2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead
+ } while (0);
+
return 0;
}
More information about the cfe-commits
mailing list