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

    <tr>
        <th>Summary</th>
        <td>
            ScopedDiagnosticHandler supports derivation but lacks a virtual destructor
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:core,
            mlir
      </td>
    </tr>

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

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

<pre>
    There are situations where we parameterize the precise selection of diagnostic handler in tools, and the lack of a virtual destructor means that doing something like the following can leak memory:

```
std::unique_ptr<ScopedDiagnosticHandler> diagnosticHandler;
if (doSomething) {
  diagnosticHandler = std::make_unique<SourceMgrDiagnosticHandler>();
}

// Do stuff under the diagnostic handler.
```

While perhaps a bit of an abuse of the API, it is perfectly legal and we should add an inline virtual destructor.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1U0uP0zAQ_jXOxaLKu_Uhh-6WFRyQkBaJ48qJJ8lQJw5-tFp-PeN0W0BbJCfxvL-Zb9Ia9dp8G8ECl_Q49EF6NLPj51V5Br5IKyfwYPEXcD-SwkKHjpxBQxeduem5QjnMxnns-ChnpcFynLk3RjuWP3JSrbFadsfoLvkJLdXSXIHzNnTeWD6BpMJ-lJ4rg_PAnaHCY7xpPF6K90Zrc46qTs5cgzxS2GTsKyv2LD2w9Pqu07ezis6r6FDsw4w_A7ws3rLi8bkzC6jDDfqnC3JWfPyrn5vy4ZIKe87ynTLPV3AsF5xt36z8fSRnxYHfAEzyCC8XFBGBCbaDL4O9B4LKUO5bYbY9_NNh_kSHHwzlDn3Pw6yoVpzRey42d4dyeX8fUROpYEe5OCKmRb8yNHPZBqKZ7jHp_uvnSCQZ0UXvnrjXr8TAQCRGemlV3GiCVlwqFcNx1jjDHaI3CTRZXYtSZEVRJqoplCiETDx6Dc1_SOEuLIux3lEii6d1S3kb_LpS7u5CJcHqZvR-cXH067gG9GNoN52ZSND6dP18WKz5QR2RiM4FoKV9qkSe5cnYCFVWSrZ9l0FRp0LUO7UVWSUyUat6l24TLVvQrmHVA8vzSSNxt--MBZLiyK5KkqpDgk2e5nmW5XUmiiovNwWUabmT20zutgCiYmUKk0S9ibg2xg6JbVaIbRgcGTU67_4YpXM4zABrecovgx-NbZwHrenP7TpUMPtk7apZW_oNgFROsA">