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

    <tr>
        <th>Summary</th>
        <td>
            [clang][StaticAnalyzer] Feature request: detect constant reference into iterator range that can change
        </td>
    </tr>

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

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

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

<pre>
    Consider the following example:

```cpp
std::vector<int> v{3, 2, 1};
auto max_iter = std::max_element(v.begin(), v.end());
auto remove_iter = std::remove(v.begin(), v.end(), *max_iter);
v.erase(remove_iter, v.end());
```

The code intends to remove the maximum element from a `std::vector`. It contains a subtle mistake, however, that the 3rd argument to `std::remove` refers to the element within the container, which may lead to surprising behaviors.

AFAIK, the latest clang-analyzer cannot detect such mistakes. Could clang-analyzer support detecting such classes of mistakes?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU0GPszYQ_TXmMlpE7ITAgUM2KdKn9tbeq4mZgFtjU3tgd_vrK0Oyzbeq-knIyMbvzXuPGYzR9I6oEYdXcbhkOPPgQ_MLOk3BZVfffTRn76LpKAAPBDdvrX8zrgd6x3GyJNRJFBdRPNay2B49TdtJ5C7dUaeFNPsg1Nk4FuonWMTxVQl5BpmWnThehHrdMDizhxHffzdMAYS6wCdLOiVLIzkWslryK_XGCVkJWSeaJSfXPbb194SBRr_Qf3BuH35IdwYhTw9Vz-xLTgFjIngq8T9qPkN6Tu63gUD7jsA4JtdF-FS8Bj_iuxnnEe7e4Rb8CAiiLL4GXBY5fGPQ3jEaFwEhzle2BKOJjH9SEjb4N1o2jTwgrxVU6ABDP6_07L-jvidUFhDoRmEVlzAPNW-GB-PWo3vdjfxtMHqAET_AEnYJFecwBRNTB11pwMX4EPPnHE7t6dvPmzACi0yRQVt0_Qs6tB9_UwCNznmGjpg0Q5xTic1bzOHsZ9t9RcR5mnx4QFLxFaUtxkgR_O2TQKg26xrV1arGjJpdWde1quW-zIamLCqqaqrUQR33UpV1pUt1pEpWiHVVlplpZCHVbrfbFwdZ7Mu8KvdaH5EKhVJ13U3sCxrR2NzaZcx96DMT40zNUcpdkVm8ko3rLEq5OhBSprEMTbr_cp37KPaFNZHjvwxs2K4DvCEOF3F4_ZWRjT7d7YvDBVpCngNBoL9miizU6ZGf9i4yOt5-LTm9tqCH1MTIPkBA19PWJxod6CHtsznYZmCeYuoQ2QrZ9oaH-ZprPwrZJnn318sU_B-kWch2dRuFbFfD_wQAAP__NqZwKA">