[patch] Fix PR c++/27279: ICE with invalid constructor declaration

Volker Reichelt reichelt@igpm.rwth-aachen.de
Mon Apr 24 18:51:00 GMT 2006


The C++ frontend ICEs on the following invalid constructor declaration:

  struct A
  {
    A(void,void);
  };

bug.cc:3: error: '<anonymous>' has incomplete type
bug.cc:3: error: invalid use of 'void'
bug.cc:3: error: '<anonymous>' has incomplete type
bug.cc:3: error: invalid use of 'void'
bug.cc:3: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in copy_fn_p, at cp/decl.c:8821
Please submit a full bug report, [etc.]

The problem is in the function copy_fn_p which at first checks the first
argument of a function:

  arg_type = TREE_VALUE (args);
  if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
     ...

Alas, this causes an ICE when the type of the first argument is invalid
i.e. an error_mark_node.

The following patch fixes that by returning early on such an invalid
argument. It returns 0 to indicate that the tested decl is not a proper
copy constructor or copy assignment operator.

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

Regards,
Volker

:ADDPATCH C++:


2006-04-24  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27279
	* decl.c (copy_fn_p): Skip functions with invalid first arg.

===================================================================
--- gcc/gcc/cp/decl.c	2006-04-23 04:48:46 +0200
+++ gcc/gcc/cp/decl.c	2006-04-23 04:49:17 +0200
@@ -8817,6 +8817,8 @@ copy_fn_p (tree d)
     return 0;
 
   arg_type = TREE_VALUE (args);
+  if (arg_type == error_mark_node)
+    return 0;
 
   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
     {
===================================================================

2006-04-24  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27279
	* g++.dg/parse/ctor4.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/parse/ctor4.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/parse/ctor4.C	2006-04-24 11:36:49 +0200
@@ -0,0 +1,7 @@
+// PR c++/27279
+// { dg-do compile }
+
+struct A
+{
+  A(void,void);  // { dg-error "incomplete type|invalid use" }
+};
===================================================================




More information about the Gcc-patches mailing list