Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}