<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78420>78420</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False positive clang-analyzer-core.uninitialized.Branch when passing initialized array to smart pointer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrchr-github
</td>
</tr>
</table>
<pre>
~~~c++
#include <memory>
void f(size_t n) {
std::unique_ptr<int[]> d(new int[n]{});
if (d.get()[0]) {}
}
~~~
~~~
[<source>:5:7: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
5 | if (d.get()[0]) {}
| ^~~~~~~~~~
[<source>:3:28: note: Storing uninitialized value]
3 | std::unique_ptr<int[]> d(new int[n]{});
| ^~~~~~~~~~~~
[<source>:3:26: note: Calling constructor for 'unique_ptr<int[], std::default_delete<int[]>>']
3 | std::unique_ptr<int[]> d(new int[n]{});
| ^~~~~~~~~~~~~~~
~~~
https://godbolt.org/z/Khaozjs9G
Originally observed with boost::scoped_array.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslMGO4ygQhp-mfCklsiGO7YMPSbq9hz3sYR-ghaFiMyKQBZxWcsizr7DT092zO5o5NLJECaiq_ytMiRD0YIlaKPdQPmViiqPzrRy9HP1q0HGc-qx36tre73cJbJ--_AnyHTCurTSTIgR-ONHJ-Svw52Xz4rTCI7A66Bu9RLTAGoTq4YoYogK-A76brP5nopdz9MAP2sZFBvBnVMBqS6-4LNq0Wu2hegLWAP8e6G3WRwRWq_VAEVidzpT7PPk88lZPD9Vvxv1-_8FIqfkhuMlLSiB8VwLfVcB3-Cq81XZI5t4LK0eUziodtbNIF2EmESlgdChwEL4XA2FaJYRyL42ww0pYYa438ivpPK0nq62OWhh9I7VeQiaxDxjEEqE64O9j4TwWn9kqn-9v42d0HPiO1YnJukhp_js6r-2An-QtJJ_U8Uemr7rFd93_Oz7C_AJn-xHnIIxJONLZEP0ko_N4dB6BVT8RzA7vTIqOYjLxRZGhFO8TV_pY9V6Ur67I9-v8zP7fn3aM8RxSStYB6wanemfi2vkBWHcD1v05Cnf7Fpo_luN_eT1oK4y5ousD-QspfNVxxN65EBfpQbozqRfhvbiuM9Vy1fBGZNQWVV5u6u02L7OxzWXFy1r0Yrtt6nJbH5mq-7KWxyo_yqIpMt2ynG3yoqiKvNhuyvWmF4JXjZCqbhpV1LDJ6SS0WRtzOSXJmQ5horaqNyzPjOjJhLktMTbXK20CY6lL-Tb5rPppCLDJjQ4xvEeJOhpqO2EC4dkFHfWF8HdfIeLrSBbPqS_aAT--g7kg6ZGHk_ARz07bSD6bvGl_uIW5a66lOwHrkqzHtDp7941kBNbNMAFYN8P-GwAA__9hA6c4">