PR c++/67913 - new expression with negative size not diagnosed
authorMartin Sebor <msebor@redhat.com>
Tue, 10 Nov 2015 02:23:34 +0000 (02:23 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 10 Nov 2015 02:23:34 +0000 (19:23 -0700)
commit685c8340ff7b5cfef7bf41c3b5e0d79ad7f7a37b
tree2e5bacc1d2b331365198e4be6156f26598c36370
parent36fa0f5f6875c49560c15dbeaed2b3c95c26687a
PR c++/67913 - new expression with negative size not diagnosed

PR c++/67913 - new expression with negative size not diagnosed
PR c++/67927 - array new expression with excessive number of elements
               not diagnosed

gcc/cp/
* call.c (build_operator_new_call): Do not assume size_check
is non-null, analogously to the top half of the function.
* init.c (build_new_1): Detect and diagnose array sizes in
excess of the maximum of roughly SIZE_MAX / 2.
Insert a runtime check only for arrays with a non-constant size.
(build_new): Detect and diagnose negative array sizes.

gcc/testsuite/
* init/new45.C: New test to verify that operator new is invoked
with or without overhead for a cookie.
* init/new44.C: New test for placement new expressions for arrays
with excessive number of elements.
* init/new43.C: New test for placement new expressions for arrays
with negative number of elements.
* other/new-size-type.C: Expect array new expression with
an excessive number of elements to be rejected.

From-SVN: r230081
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new43.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/new44.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/new45.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/new-size-type.C