Skip to content

False positive clang-analyzer-core.uninitialized.Branch when passing initialized array to smart pointer #78420

Open
@chrchr-github

Description

@chrchr-github
#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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions