From d4a906e7b51f3fc31f3328810f45ae4cf2e7bbc3 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 25 Sep 2020 14:31:46 -0400 Subject: [PATCH] analyzer: add test for placement new gcc/testsuite/ChangeLog: PR analyzer/94355 * g++.dg/analyzer/placement-new.C: New test. --- gcc/testsuite/g++.dg/analyzer/placement-new.C | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/analyzer/placement-new.C diff --git a/gcc/testsuite/g++.dg/analyzer/placement-new.C b/gcc/testsuite/g++.dg/analyzer/placement-new.C new file mode 100644 index 00000000000..8250f45b9d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/analyzer/placement-new.C @@ -0,0 +1,26 @@ +#include + +/* Placement new. */ + +void test_1 (void) +{ + char buf[sizeof(int)]; + int *p = new(buf) int (42); +} + +/* Placement new[]. */ + +void test_2 (void) +{ + char buf[sizeof(int) * 10]; + int *p = new(buf) int[10]; +} + +/* Delete of placement new. */ + +void test_3 (void) +{ + char buf[sizeof(int)]; + int *p = new(buf) int (42); + delete p; // { dg-warning "memory not on the heap" } +} -- 2.30.2