re PR c++/53330 (new() operator can return NULL on a zero-length allocation)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 12 Aug 2015 22:38:04 +0000 (22:38 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 12 Aug 2015 22:38:04 +0000 (22:38 +0000)
2015-08-12  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/53330
* g++.dg/init/new42.C: New.

From-SVN: r226840

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new42.C [new file with mode: 0644]

index 20735b946b67d88992541c1180c3f2b7280dc025..1b49702fd74d7b7cf1617d8a3ad93ff02dc5fde1 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/53330
+       * g++.dg/init/new42.C: New.
+
 2015-08-12  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR target/67071
diff --git a/gcc/testsuite/g++.dg/init/new42.C b/gcc/testsuite/g++.dg/init/new42.C
new file mode 100644 (file)
index 0000000..12a714a
--- /dev/null
@@ -0,0 +1,42 @@
+// PR c++/53330
+// { dg-do run }
+
+extern "C" void abort ();
+
+struct constr_empty
+{
+    constr_empty() {};
+};
+
+struct noconstr_empty
+{
+};
+
+struct constr_nonempty
+{
+    constr_nonempty() {};
+    int dummy;
+};
+
+struct noconstr_nonempty
+{
+    int dummy;
+};
+
+int main()
+{
+    volatile constr_empty      *ce = new constr_empty[0];
+    volatile noconstr_empty    *ne = new noconstr_empty[0];
+    volatile constr_nonempty   *cn = new constr_nonempty[0];
+    volatile noconstr_nonempty *nn = new noconstr_nonempty[0];
+    volatile int               *ii = new int[0];
+
+    delete [] ce;
+    delete [] ne;
+    delete [] cn;
+    delete [] nn;
+    delete [] ii;
+
+    if (!(ce && ne && cn && nn && ii))
+      abort ();
+}