aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-01-21 12:49:03 -0500
committerJason Merrill <jason@redhat.com>2022-01-21 14:40:09 -0500
commit847a8301add0a316767878342c1367948835c181 (patch)
tree493d8dfff742fd81b3af794d6c569b61b72f6f0b /gcc
parentc163647ffbc9a20c8feb6e079dbecccfe016c82e (diff)
downloadgcc-847a8301add0a316767878342c1367948835c181.zip
gcc-847a8301add0a316767878342c1367948835c181.tar.gz
gcc-847a8301add0a316767878342c1367948835c181.tar.bz2
c++: class array new checking [PR104084]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/init.cc2
-rw-r--r--gcc/testsuite/g++.dg/init/new50.C9
2 files changed, 10 insertions, 1 deletions
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 668a84d..1f04783 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -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
index 0000000..981d231
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new50.C
@@ -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]; }
+};