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

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] create a check that looks for constructing a string from a nullptr
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            good first issue,
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    Consider the following code:

```
std::string foo()
{
    return nullptr;
}
```
See [compiler explorer example](https://godbolt.org/z/azW348cbd)

This code compiles just fine with no warnings or errors, but crashes when you run it.  We should be able to detect cases where a `nullptr` is used to construct a string, at least in the simple case above.  I had a real-world bug that was exactly the above scenario, although I have simplified the example to remove irrelevant code. Obviously more sophisticated data flow analysis can propagate `nullptr` through usages until it hits a `std::basic_string` constructor, but even detecting the above simple case would be a useful start.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxslFFr6zgThn-NcjM0OHKcxhe-aBsCH3ywF7twLhdZGls6R9EEzSjZ9NcvcpO2HBaMLNszmtHzvrJhDnNCHFT3qrrDyhTxlIf_42xieMcXV6J4Ircayd2GN0ocHGYQjzBRjHQNaQZLDlX7opqDah7jrrlfyyOLqwHtC0uuGROR0nul-3v08-vHBAAgo5ScIJUYz5JV-_qIOfzn0n8igupeLZ3OIWIG_OccKS8TczpHVN1B6b0XOXNtQR-VPs7kRoqypjwrfXxX-mjef7TbvR3dV0_L-JcPvOwP7gUYfhYWmEJCuAbxkAiuJqeQZgbKgDlTZqXfYCwCNhv2yHD1mOBGBXJJEGQN8AOBPZXoYEQwY0QQAoeCVsAa_sjJCAbUrnmw2DUQGAqjq9GWEksuVsDAB9da1ghENCwQ0iITh0phWRPMSBdcA_wPvHFgIKOJT1fKtYsyg3gjcDVc0VmJtyV_yQG2mEwOtFSoliizX5a53CuEKdSuPD641w4znmpyyBkjXkySBeUa_hgvgQrHG5woIzCdfWAJ1gg6cEYMTJGuYJKJN64CmATnTGczG8HfgIjPSzOFzYwMJUmIEAR8EP6g92m-0XCwf99R7ZovgJQfguEF012G6tNvAL5hvH7qVrWYSgQWk2W9ckPr-rY3Kxw2z5tu1_V73a38sB9bp_XYOpys27qd2zbjNLlN2_abve3cKgy60dum22yb7abR3brXerfptw67vh_7Z622DZ5MiOsYL6fq21VgLjj0utltVtGMGHk5w1pj8iZZPGESpbXSb0rrmcjBFHK1Rc37_GCjSfOTBHerr7rDKg-1wtNYZlbbJgYW_qopQeLyq_iW1h3AZqy6GLAe7a8PG0WiXwwT5S_KFejDqTBlOoF5nPJVyXH47YwG8WVcWzopfawd3G9P50w_0YrSx2UrrPRxofBvAAAA__-u-ZkO">