analyzer: add test for placement new
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 25 Sep 2020 18:31:46 +0000 (14:31 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Sat, 26 Sep 2020 01:34:20 +0000 (21:34 -0400)
gcc/testsuite/ChangeLog:
PR analyzer/94355
* g++.dg/analyzer/placement-new.C: New test.

gcc/testsuite/g++.dg/analyzer/placement-new.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/analyzer/placement-new.C b/gcc/testsuite/g++.dg/analyzer/placement-new.C
new file mode 100644 (file)
index 0000000..8250f45
--- /dev/null
@@ -0,0 +1,26 @@
+#include <new>
+
+/* 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" }
+}