public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6808] c++: class array new checking [PR104084]
@ 2022-01-21 20:18 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-01-21 20:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:847a8301add0a316767878342c1367948835c181

commit r12-6808-g847a8301add0a316767878342c1367948835c181
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 21 12:49:03 2022 -0500

    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.

Diff:
---
 gcc/cp/init.cc                    | 2 +-
 gcc/testsuite/g++.dg/init/new50.C | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 668a84d969e..1f047831b6d 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 00000000000..981d23106f3
--- /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]; }
+};


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-21 20:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 20:18 [gcc r12-6808] c++: class array new checking [PR104084] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).