As reported in the following post: https://gcc.gnu.org/ml/gcc-help/2016-05/msg00113.html the -Wplacement-new warning introduced in GCC 6.1 issues a false positive on the following test case. It seems to treat the array element as if it was the array itself. $ cat zz.cpp && /build/gcc-6-branch/gcc/xgcc -B /build/gcc-6-branch/gcc -S -Wall -Wextra zz.cpp void* operator new (__SIZE_TYPE__, void *p) { return p; } struct S { char c [32]; } *p [2]; void f () { new (p [0]) S; } zz.cpp: In function ‘void f()’: zz.cpp:7:12: warning: placement new constructing an object of type ‘S’ and size ‘32’ in a region of type ‘S* [2]’ and size ‘16’ [-Wplacement-new=] new (p [0]) S; ~~~~^
Patch posted for review: https://gcc.gnu.org/ml/gcc-patches/2016-05/msg02208.html
Author: msebor Date: Mon May 30 22:56:43 2016 New Revision: 236902 URL: https://gcc.gnu.org/viewcvs?rev=236902&root=gcc&view=rev Log: PR c++/71306 - bogus -Wplacement-new with an array element gcc/cp/ChangeLog: 2016-05-27 Martin Sebor <msebor@redhat.com> PR c++/71306 * init.c (warn_placement_new_too_small): Handle placement new arguments that are elements of arrays more carefully. Remove a pointless loop. gcc/testsuite/ChangeLog: 2016-05-27 Martin Sebor <msebor@redhat.com> PR c++/71306 * g++.dg/warn/Wplacement-new-size-3.C: New test. Added: trunk/gcc/testsuite/g++.dg/warn/Wplacement-new-size-3.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/init.c trunk/gcc/testsuite/ChangeLog
Author: msebor Date: Tue May 31 17:24:22 2016 New Revision: 236934 URL: https://gcc.gnu.org/viewcvs?rev=236934&root=gcc&view=rev Log: PR c++/71306 - bogus -Wplacement-new with an array element gcc/cp/ChangeLog: 2016-05-31 Martin Sebor <msebor@redhat.com> PR c++/71306 * init.c (warn_placement_new_too_small): Handle placement new arguments that are elements of arrays more carefully. Remove a pointless loop. gcc/testsuite/ChangeLog: 2016-05-31 Martin Sebor <msebor@redhat.com> PR c++/71306 * g++.dg/warn/Wplacement-new-size-3.C: New test. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/warn/Wplacement-new-size-3.C Modified: branches/gcc-6-branch/gcc/cp/ChangeLog branches/gcc-6-branch/gcc/cp/init.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Fixed in 7.0 via 236902 and backported to 6.x in r236934.