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

    <tr>
        <th>Summary</th>
        <td>
            AddressSanitizer doesn't catch `std::vector` OOB access with `std::views::take`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            libc++,
            compiler-rt:asan
      </td>
    </tr>

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

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

<pre>
    The following is caught by AddressSanitizer:
```cpp
auto const v = std::vector<int>{0, 1, 2};
std::println("{}", std::ranges::fold_left(v.begin(), v.end() + 1, 0, std::plus{})); // asan crash here
```

Changing to `std::views::take(v.size() + 1)` seems to mask this error:
```cpp
auto const v = std::vector<int>{0, 1, 2};
std::println("{}", std::ranges::fold_left(v | std::views::take(v.size() + 1), 0, std::plus{})); // prints 3
```

**Repro:** https://godbolt.org/z/5P4sdzhb1

We should identify why (hopefully only some) range adaptors are hiding the overflow access so that they're consistent with the underlying range's bounds checking, and so that ranges are more safe to use.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVMGO4zYM_Rr6Qkwgy0kcH3xIJs11i7ZAj4Vs0ZZ2FMkQ5QSZry9kz87uzGHRHhcgZEsiH8lHUorZjp6ohd0JdudCzcmE2PZfdVd0QT_avwzhEJwLd-tHtIy9mkeTsHvgUetIzH8qb5N9pQjVEcQZxBH2YpV-mtYTNaeAffCc8IZQnZGTzurV8UZ9ChGqZ-sTVL9BfRIgn7HMi4T6DNVphXi3mKL1yXmQB5AS6lNWkjLrv6tE5Ufi9X8ITv_jaEggD7dNR6NdTZtscduQ1-sWQZ5Wt-ID1uRm_ualyVKdEOQF5AUVK499VGzQUKRPyb9tl_XZKD9mAlNA2Ivv2Vu6v8WZ1AstIbJ9pY8hNbAXyERXzvZXxS-YjGWkGMOvwDpC_YPaf835_1RiiY6x-kkJQGb5g6YYMtyyQ5PStMSywIxBd8GlTYgjyMsryMvu9y3rV9OVPyL9TcgmzE6j1eSTHR54Nw8EeTBhomF27oHBuwdyuFJOaSEGlVZTCpFRRUJj9dIOhjDcKA4u3FH1PTEjB0xGpXz3AFlHWkpoOZFPeLfJLFaz1xTdI4Ms8CBrxi7MXjP2hvoX68fMnvL6HXEt0OL_GiIhq4FyR81Mm0K3lW6qRhXUlrU4SFHWO1GYdtBNo_dU1krW1WFbDs2wF2XT7GjYDsNeF7aVQm6FLGspZFOKzbZpqrLqto2o9FZ2B9gKuirrNs7drpncwjLP1B5kKevCqY4cL--PlOSN8j1dyae1u0BKZ7se5GmRt6M-XCfrKD7FBNUxj2G-2p2L2GYfT908MmyFs5z4u9dkk6P286uFOhB7kHXCXqXefJzPdU72Ar98OX0r0FKDn03xXhRzdO2n5rLJzN2mD1eQlxzT2-dpiuEr9QnkZaGFQV4WZv4NAAD___COq8g">