-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
Description
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
.