Skip to content

[analyzer] Placement new checker for arrays result in false positive #56264

@isuckatcs

Description

@isuckatcs

When placement new is used to create and array of elements at a specific location, a warning is falsely reported.

#include <new>

struct s {
  int x;
};

int main() {
  s arr[4];
  new (arr + 1) s[1];
  ^~~~~~~~~~~
  warning: 12 bytes is possibly not enough for array allocation which requires 4 bytes. Current overhead requires the size of 8 bytes [cplusplus.PlacementNew]

  return 0;
}

The warning is only reported in case of arrays with both trunk and 14.0.0 clang.
Writing new (arr + 1) s doesn't end up with a warning, but new (arr + 1) s[1], new (arr + 1) s[2], etc. all do.
Feel free to check the snippet on godbolt: https://godbolt.org/z/dvz9nqPne. Compile only using --analyze.

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