Skip to content

[clang-tidy] False negative performance-inefficient-string-concatenation in do-while loop #186362

@chrchr-github

Description

@chrchr-github
#include <string>

void f(std::string& s) {
    int i = 0;
    do {
        s = s + "def"; // false negative
    } while (i < 10);
}
void g(std::string& s) {
    int i = 0;
    while (i < 10) {
        s = s + "def"; // warning
    }
}
<source>:12:9: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation]
   12 |         s = s + "def";
      |         ^
1 warning generated.

https://godbolt.org/z/sj8P5oGKa

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions