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

    <tr>
        <th>Summary</th>
        <td>
            Clang-tidy should detect undefined behaviour on container access
        </td>
    </tr>

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

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

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

<pre>
    Hi,

Spent the day tracking down a segfault that turned out to be because we where calling front on a std::deque and then de-referencing it to call a value on that returned element, but because we hadn't checked the size of the deque first we hit a segfault if it was empty as that's undefined behaviour. Just wondering if there's a clang-tidy check for calling these methods on collections (std::list's front method is also undefined on an empty list)?

Thanks in advance!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsksFy4jgQhp9GvnRB2bLB8cGHbFLU1l43L9CW2pYmQmKkFhTz9FOymYTDXODSf39f_zKmZBdPNIrDP-LwXmFmE-L4gYnvsmmrKej7-K8V8k3U76J-3X7_v5BnYEOg8Q4cUX1av4AONw8IiZYZsysDyMA5etIQMgMHmAgmUpgTwY3gZigSKHSuxOcYPENYV7AW7atoXzX9zATodaF50LSLNFMkr0rCrjtLHhCu6DKV-IqN9ACTozN5FvINpszPdIPaC9kzKEPqk1YEJPuLIMzbcSt8tjHxOm_5-To7F_4NE9D5wnfAtJKF7BNkr2m2BT-RwasNOe7hv1z2BK8prvIrJNIaQFAO_bJjq--bD8whflXDhhLBmdgEncqNKjhHim3wCYR8-erL2bQZbGVuCbAJ0KXwpFVa9g_xLTOI9vT8xh8G_WcC6wH1Fb0iIZtKj60e2gErGpu-rbt-6PquMqPs-kOtm2EeZmwb3XRzraZJDcfhpT72x7myo6xl1zR10xy7ru32LdZH3fdSDS_T4agOoqvpjNbtnbue9yEulU0p09g03aGvK4cTufTnK41jmdpNeUmiq4t_-s6xZUfj23edyYTsNGhiUvy3p9kK9YzWUwRUilKqcnSjYb6kUqw8CXlaLJs87VU4C3kquMff7hLDD1Is5Gl1TkKeHtrXUf4OAAD__yXEJHU">