<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114125>114125</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Question about the warning option for the clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
i80287
</td>
</tr>
</table>
<pre>
Compilation of the following code produces 2 warnings about potential null pointer dereference and null pointer dereference when compiled by the gcc with flags `-O2 -Wnull-dereference`.
This code contains ub and compiler is not obligated to warn about it, but is it possible to add additional warning option to the clang so that it reports about possible null pointer dereference like gcc does?
```cpp
#include <cstdint>
#include <vector>
auto f(std::uint32_t n) {
std::vector<std::int32_t> v(n + 1);
v[0] = 1;
return v;
}
int main() {
f(static_cast<std::uint32_t>(-1));
}
```
On the godbolt
https://godbolt.org/z/4q4bqcx5G
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0k8GO4zYMhp-GvhAJZCp27IMPM5NNj4sCBXpcyJLiqFUkr0Qn3T59YTszyS46QGJbpPTz4w9K5eyGYG0H1StUh0JNfI6pc42gZl_00fzo3uJldF6xiwHjCfls8RS9jzcXBtTRWBxTNJO2GQlvKgUXhoyqjxPjGNkGdspjmLzHMbrANqGxyZ5sskFbVMF8nrydbUC9AFiD_Y-l-qA13hyf8eTVkBFqsflKuPlzVtk8nYZabEEcQLz8cXZ5RdUxsHIh49Qvle_aCV3GEBlj792g2BrkuDRzb8Qx0Bv281dGNzeWs-u9nbcpY-a_mx1S_t0CjONiGccFWnsVBszzQs1ymOwYEz-Muut9aoV3f6-tm2gzyOPaGdRi_elxvEdIuqD9ZCyCfNOZjQsM8sv_Za9Wc0yP5PJUE0c8ATWZDcgXkC-TCyzpG2MAahH2r-tGRMSPPe9Sbx-R-yGQX_AK1AQEesUSqAX5JHCF6lVAdUCQByx_SiXLUwp4_QjC_vAM6gLjRbkA1PzMtcIrdvqbVpmfoaYHFVCzWXCeiB4V3n1dl1_DOnnR9NHzGjszj3lWpSPQ8Z7axjQAHf8FOu6-7_rv-p_qt8J00rSyVYXtyr0UJGXV7ItzJ0vT1lXTiEpQeypNTX0pSKo9WV3WO1u4jgTtSkEtCappv1WlUK3eqbolYWzdw07Yi3J-6_31MtcuXM6T7cpyV1JVeNVbn5e7TbRMIBDN1zx184FNPw0ZdsK7zPkhwY697X6fbF4GeB3Quf1fJvsU02O0iyn57hdLHJ-nfqvjBeg4q99fmzHFv6xmoONCm4GOd-BrR_8FAAD__2Ppb40">