Bug 71306 - bogus -Wplacement-new with an array element
Summary: bogus -Wplacement-new with an array element
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.1.0
: P3 normal
Target Milestone: ---
Assignee: Martin Sebor
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2016-05-27 03:59 UTC by Martin Sebor
Modified: 2016-05-31 17:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 6.1.0, 7.0
Last reconfirmed: 2016-05-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2016-05-27 03:59:14 UTC
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;
        ~~~~^
Comment 1 Martin Sebor 2016-05-27 16:34:07 UTC
Patch posted for review:
https://gcc.gnu.org/ml/gcc-patches/2016-05/msg02208.html
Comment 2 Martin Sebor 2016-05-30 22:57:15 UTC
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
Comment 3 Martin Sebor 2016-05-31 17:24:53 UTC
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
Comment 4 Martin Sebor 2016-05-31 17:26:17 UTC
Fixed in 7.0 via 236902 and backported to 6.x in r236934.