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

    <tr>
        <th>Summary</th>
        <td>
            `clang-tidy` check request: a `new` expression that is implicitly converted to `bool`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            check request
      </td>
    </tr>

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

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

<pre>
    Consider the following code:

```cpp
struct S {};

void f(bool flag);

void g() {
  // Check should fire here:
  f(new S());
}
```

This `new` expression seems clearly a bug. This feels like a case `clang-tidy` could error on easily, similar to other bugprone checks. It might even make sense as a warning. The only use case I can imagine where this isn't a bug due to leaking memory is for types that register themselves in some collection when heap allocated, so the pointer produced by `new` isn't actually needed and can be used as a bool. But it is *always* true, and so it seems much more clear to write:

```cpp
void g() {
  (void)new S();
  f(true);
}
```

And not get a warning. This seems to more clearly show that the result of the `new` expression is *intentionally* discarded.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVNGOqzYQ_RrzMtoITBbIAw_JriLd59sfMPYA7hqbeoZQ_r4y3PZm261aKUoUGJ8558wZKyI7eMRWvN7E63umFh5DbPWovHEYddYFs7VvwZM1GIFHhD44F1brB9DBoCivIn8X-Z_fVX589DwfT4jjohm-g6hvon4X5e25_hGsgV7IpgvBQe_UIOTlq5pByEbIy46yPwUQ8i7kHd5G1B9AY1icgd5GhBHjT16ww3tc4fsB8alB_f433s-Nfxktgahyj6uocsDf54hENnggxIlAO1TRbaCgW4YT7OU9oiNw9gNBgVaECUA75YcXtmZLOHpnijGGCMEDKrJuE_INyE7WqQgcIPCIMcHOMXgEnTTSCb4xTHYYGfCBHib1gUDoCUERKFhV9NbvTBCCdxsshAeJb6CVBzupwXqENTkEnPha8kLWfGgAs2Dq7lB9pAFPOIW4QZIVIvA2IwGPiiHiYImPQEyE7oEE1gOFCUEH51Bzsmkd0cOIagblXNCK0ew6wx6kOVifMOYYzKLRQLc9uf0XMc2Lcm4Dj2jQgPJm19JhUmcO5Sk9J7gtDJYTXSGvyq1qIyGvwHHB1DadpJAqjvFNix5hChGPQSbha7T835H-90A26ZWQl-e4lbfnIB5k_m8Cr96ADwwD8uf5WvohgsOTBLelPViPGSWLI9LiGEK___syyodbaRI-zSxZnUwzlrSKBs0pM21pLuVFZdgW1aWQxeVS1NnYGjz3aBo8503fyQbrojFVXhWm7GUjFWa2lbks8yZ_zeuiKesTqrIwRdOfUVV1fe7FOcdJWXdy7jGdQhwyS7RgW53PVZE51aGj_WaSct8AiPjbgsRCynRZxTade-mWgcQ5d5aYfiKxZYftP5fvE055BfW1LbuFaT-m2Vlt2W2gg39gZDTJdFHlKXSiyrMlunZknikFZ7-TBsvj0p10mIS8J0Y_fl7mGH5FzULed6Ek5H3X-kcAAAD__2USv1w">