]> gcc.gnu.org Git - gcc.git/commitdiff
c++: class array new checking [PR104084]
authorJason Merrill <jason@redhat.com>
Fri, 21 Jan 2022 17:49:03 +0000 (12:49 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 21 Jan 2022 19:40:09 +0000 (14:40 -0500)
My patch for PR20040 made us stop exiting early from build_new_1 in
cases of trivial initialization if there's a class operator delete; as a
result, code later in the function needs to handle this case properly.

PR c++/104084
PR c++/20040

gcc/cp/ChangeLog:

* init.cc (build_new_1): Only pull out TARGET_EXPR_INITIAL if
alloc_expr is a TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/init/new50.C: New test.

gcc/cp/init.cc
gcc/testsuite/g++.dg/init/new50.C [new file with mode: 0644]

index 668a84d969e57bb3771f0bf049048d4d08686ea4..1f047831b6dac32df74b833b4ec4f2e6806a1a42 100644 (file)
@@ -3786,7 +3786,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
   if (cookie_expr)
     rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval);
 
-  if (rval == data_addr)
+  if (rval == data_addr && TREE_CODE (alloc_expr) == TARGET_EXPR)
     /* If we don't have an initializer or a cookie, strip the TARGET_EXPR
        and return the call (which doesn't need to be adjusted).  */
     rval = TARGET_EXPR_INITIAL (alloc_expr);
diff --git a/gcc/testsuite/g++.dg/init/new50.C b/gcc/testsuite/g++.dg/init/new50.C
new file mode 100644 (file)
index 0000000..981d231
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/104084
+
+int nothrow;
+struct MaxAlignedAllocable {
+  void *operator new[](__SIZE_TYPE__, int);
+  void operator delete[](void *);
+  long Resize_size;
+  void Resize() { new (nothrow) MaxAlignedAllocable[Resize_size]; }
+};
This page took 0.070716 seconds and 5 git commands to generate.