<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59478>59478</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            detect temporary `std::string` generation with `performance-inefficient-string-concatenation`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          firewave
      </td>
    </tr>
</table>

<pre>
    ```cpp
#include <string>

extern void cb(const std::string&);

void f1(const std::string& s1, const std::string& s2) {
    std::string str = s1 + "..." + s2;
 //std::string str = s1;
    //str += "...";
    //str += s2;
 cb(str);
}
```

https://godbolt.org/z/G1zzh81fM

If I understand it correctly (based on `callgrind` output) the code will create a temporary string object and assign it to the variable and destroy the temporary one. Assigning/constructing the new object with the first part and appending to it will avoid creating that object.

(Yes, I am aware in this case the temporary object it could simply be inlined - this is a reduced example).

`llvm-mca` seems to support this as well:

before:
```
Iterations:        100
Instructions: 10700
Total Cycles:      8864
Total uOps:        13700

Dispatch Width:    4
uOps Per Cycle:    1.55
IPC:               1.21
Block RThroughput: 34.3
```

after:
```
Iterations: 100
Instructions:      7300
Total Cycles:      6697
Total uOps: 9700

Dispatch Width:    4
uOps Per Cycle:    1.45
IPC: 1.09
Block RThroughput: 24.3
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVcFu6zYQ_Br6srBAUbYsHXRI4rrIoehD8YCiR4paWWxpUiBX8XO-viAlx07aBAWqBLKt2ZldDpcrGYI-WsSGbR_Zdr-SEw3ON732eJYvuGpdd2lYyed_NY6M7xl_YKLQVpmpQ2DFUyCv7ZEVPy1guuMPQm_hxekOVMtEpZwNBIE6Vjyw4mEhiZKJmhWP99TE6fMvOBByJp7gc1gwUQPbLbIA8DEKAnlgxR5CDkw8AhMiyzImRPoVxFtJwMSBicPn9FskwFuwjzIRf9P9Ouw-YXIrk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