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

    <tr>
        <th>Summary</th>
        <td>
            Clang does not throw out useless vector::resize() with new/delete code during optimization.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    https://godbolt.org/z/deTsM91P9

```cpp
#include <array>
#include <exception>
#include <vector>

void append_column_descriptions(std::vector<int> &iovecs) {
    const size_t new_size = iovecs.size() + 5;

    if (new_size > iovecs.capacity() || new_size > 1000) std::terminate();

 iovecs.resize(new_size);
}
```

As you can see, `new_size > iovecs.capacity()` is an assertion that means `.resize()` will never exceed `.capacity()`. This means that the compiler can definitely not include `realloc` code when inlining `vector::resize()`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElMmO4ywQx58GX0ptEfASH3zI0r590nfoe0SgOmYGgwU4mfTTj3CcXjLTGsnCS1X9-FdRZRGCPlnElpRbUu4zMcXe-TY4-RPjKLTPjk5d2z7GMRC-IawjrDs5dXQm5s6fCOveCOsUvoT_mtX_DaF7QjfLWtHbJcdx-cK4ttJMCoHwnfBeXAl__psNf0kco3b2G_sZZXT-wzivZ6cViHFEqw7SmWmwB4VBej2TAmHrEFXKgm_u8TttI-HPQFil3RllIKwBUm9vQAAA6WyIEPQbHiJYvBzSIxC-h1tAnt4JW8-BbAsl4dvPohJDvwJh60_Bz_dgKUYhdbzeAfWO1Dv44rmilCbbu_aIftBWxGXXx_0WssdF2B32xbXeP5zRZ8QmwNVNIIWFgEjYDkhF_62eVBR0AGFBhIA-1RxiLyIMKGxIjA9Ri_tFGwMWz-ghnTiq2esPbA4vvQ4LZ0bGHkG6YdQG_SxU4au2OqK5gnUR3luloh6FMU6m7aRTCJceLWhrtNX2lBzuvZBq-yAwz1TLVcMbkWG7qlnJGkppnfWtZFyt-ZG9soIW67KqlVzzom5KRQtRCJbpllFW0IayVbnirM4rIRXypqzrsqhqviIFxUFokxtzHtIsZTqECdsVrSmlmRFHNGGeS8akEfZEGEsj6tsU8HScToEU1OgQwwci6miw3SV3UA7DXIzYe3cBN0WYAhoMAb5LGS469qn95pk2GPFWMzX5VCw3Rj3oN5GONs8mbx5_DDr20zGXbiCsS5qW29Po3Q-UkbBuzjEQ1i1pnlv2OwAA__87ZGPD">