c++: add test [PR105265]
authorJason Merrill <jason@redhat.com>
Wed, 13 Apr 2022 16:44:54 +0000 (12:44 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 14 Apr 2022 00:22:18 +0000 (20:22 -0400)
This was fixed by r12-1165, but good to have a test that doesn't need
-fno-elide-constructors.

PR c++/105265
PR c++/100838

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-new6.C: New test.

gcc/testsuite/g++.dg/cpp0x/initlist-new6.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-new6.C b/gcc/testsuite/g++.dg/cpp0x/initlist-new6.C
new file mode 100644 (file)
index 0000000..0ef2780
--- /dev/null
@@ -0,0 +1,39 @@
+// PR c++/105265
+// { dg-do run { target c++11 } }
+
+int c;
+
+class Block
+{
+public:
+  Block(int n) : data{new char[n]}, size{n}
+  {
+    ++c;
+  }
+
+  ~Block()
+  {
+    --c;
+    delete[] data;
+  }
+
+private:
+  char* data;
+  int size;
+};
+
+struct Cargo
+{
+  Block const& block;
+};
+
+int main()
+{
+  {
+    Cargo* c = new Cargo{{4000}};
+    delete c;
+  }
+  if (c != 0)
+    __builtin_abort ();
+  return 0;
+}