gcc-patches@gcc.gnu.org
[Top] [All Lists]

[patch] Fix PR c++/28593: ICE on invalid operator new

Subject: [patch] Fix PR c++/28593: ICE on invalid operator new
From: Volker Reichelt
Date: Fri, 04 Aug 2006 10:17:53 +0200 CEST
The following invalid code snippet triggers an ICE since GCC 4.0.0:

  void *p = new (::X;

bug.cc:1: error: '::X' has not been declared
bug.cc:1: error: expected type-specifier before ';' token
bug.cc:1: internal compiler error: tree check: expected tree_list,
have error_mark in resolve_args, at cp/call.c:2710
Please submit a full bug report, [etc.]

The compiler tries to interpret this as a placement new with invalid
placement (error_mark_node). However, build_new and its callees do not
handle this case correctly.

The patch below fixes this by improving the sanity checks at the
beginning of build_new.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?

Regards,
Volker

:ADDPATCH C++:


2006-08-04  Volker Reichelt  <reichelt@xxxxxxxxxxxxxxxxxxx>

        PR c++/28593
        * init.c (build_new): Return early on invalid placement.

===================================================================
--- gcc/gcc/cp/init.c   (revision 115898)
+++ gcc/gcc/cp/init.c   (working copy)
@@ -2063,7 +2063,7 @@ build_new (tree placement, tree type,
   tree orig_nelts;
   tree orig_init;
 
-  if (type == error_mark_node)
+  if (placement == error_mark_node || type == error_mark_node)
     return error_mark_node;
 
   orig_placement = placement;
===================================================================

2006-08-04  Volker Reichelt  <reichelt@xxxxxxxxxxxxxxxxxxx>

        PR c++/28593
        * g++.dg/parse/new3.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/parse/new3.C       2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/parse/new3.C       2006-08-03 22:38:27 +0200
@@ -0,0 +1,4 @@
+// PR c++/28593
+// { dg-do compile }
+
+void *p = new (::X;  // { dg-error "declared|type-specifier" }
===================================================================


<Prev in Thread] Current Thread [Next in Thread>