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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Warning when block captures a pointer to pointer or reference
        </td>
    </tr>

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

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

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

<pre>
    Blocks implicitly captures all variables.

In a pure Objective-C codebase, any pointer type is likely to be a pointer to an Objective-C type, reference counted, and ARC will ensure that the object is correctly retained by the block (if necessary).

When working in Objective-C++ codebase on the other hand, it is frequent to have pointer or reference to C++ types as local variable. Since those are not reference counted, it is highly possible for the pointer or reference to become dangling by the time the block is executed (especially if the block is posted to a background queue to be executed later).

This can leads to security vulnerability in the product due to an use-after-free.

It would be good to have warnings (that can be treated as errors with `-Werror`) when a block captures either `this`, a pointer to a C++ type (except a pointer to method or a pointer to function), a reference.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE1v4zYQ_TX0ZWBDpmXFOuiQZBGgpwJtgZyH5Eiahia1_LBX_76g5DjrxfZkmJp5b957Q2KMPDiiThxfxPHbBnMafeiioT5QdLRR3szdi_X6IwKfJ8uak51B45RyoAhoLVwwMCpLcSeqZ1E9_-EAYcqB4E_1L-nEF9q-gvaGFEYS8hXQzTB5dokCpHki4AiWP8jOkDwoKv2fnz2gewAqDQUkUE-BnCbQPrtEZkU28PzXK1zZWiAXyxRpxARpJPALSiHTPgTSRUmghOzIgJqXGlW0gpAn7sGRphgxzEK2N23vIzm4-vDBbgB-GEzIFyFf7jrBu5U0jRRgRLfMxwt9H-h7JpeKuhEvdFfrw0-ykodP0KI5AkawXuOX4zv4m5fK0UcCDATOp98bsxKPPIy2eB8jK0vQ-7AM-X_8irQ_Exh0gy2KbyYlPtNPbnEE-kE6JzLFOYoTaUZrZ-D-sWzysRSVUEGh_hiCz87A90z5xveFZDFR-HL-n7Hkhg4soYmlOJLOgdMMl2wdBVRsyz9efZ-CN1knMCsyOsiRttgnCts-EH0ua4Krz9YU6sF7c4_kisGxG2JRtGxQ4VYEKRCW8TACheBDhCunEURTbd-XA9FUQrZwLZuCN-n3-0K8rINoqjRyXEpff9n2h9AXP39omtJj1ZnS6E3J6-G4z04n9k7IdgW-p7nbmO5g2kOLG-r2T3X7VB-rqt6M3Qn7vW6eTg02yjSyag_q1Lan9umgqr067DfcyUoeq2Yv982-qeudqVVtTLWvzbFW-kSiruiMbHfWXs47H4YNx5ip29eHVtYbi4psXJ4YKbVFNwgpy2sTutKwVXmIoq4sxxS_IBInu7xLa8fxG7yviazO_uLrgwu_2-ZNDrYbU5qiODwL-Sbk28BpzGqn_VnIt8J7-9lOwZdbLeTboiMK-XaTcunkfwEAAP__kkTIgw">