This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c++/23089, ICE on incomplete function parameter


Consider the following C++ testcase:

  void foo(struct A) {}

When compiling this with -O we get an ICE after a sensible error message:

  PR23089.cc: In function 'void foo(A)':
  PR23089.cc:1: error: '<anonymous>' has incomplete type
  PR23089.cc:1: error: forward declaration of 'struct A'
  PR23089.cc:1: internal compiler error: in int_mode_for_mode, at stor-layout.c:248

The following patch fixes the ICE by marking the function parameter as
invalid after it has been diagnosed as incomplete. (We already did this
for a void parameter.)

Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline and 4.0 branch (since it's a regression)?

Regards,
Volker


2005-08-17  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23089
	* decl.c (require_complete_types_for_parms): Mark incomplete types
	as invalid.

===================================================================
--- gcc/gcc/cp/decl.c	15 Aug 2005 20:38:14 -0000	1.1418
+++ gcc/gcc/cp/decl.c	18 Aug 2005 15:20:22 -0000
*************** require_complete_types_for_parms (tree p
*** 8305,8318 ****
      {
        if (dependent_type_p (TREE_TYPE (parms)))
  	continue;
!       if (VOID_TYPE_P (TREE_TYPE (parms)))
! 	/* grokparms will have already issued an error.  */
! 	TREE_TYPE (parms) = error_mark_node;
!       else if (complete_type_or_else (TREE_TYPE (parms), parms))
  	{
  	  relayout_decl (parms);
  	  DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
  	}
      }
  }
  
--- 8305,8320 ----
      {
        if (dependent_type_p (TREE_TYPE (parms)))
  	continue;
!       if (!VOID_TYPE_P (TREE_TYPE (parms))
! 	  && complete_type_or_else (TREE_TYPE (parms), parms))
  	{
  	  relayout_decl (parms);
  	  DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
  	}
+       else
+ 	/* grokparms or complete_type_or_else will have already issued
+ 	   an error.  */
+ 	TREE_TYPE (parms) = error_mark_node;
      }
  }
  
===================================================================


2005-08-17  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23089
	* g++.dg/other/incomplete1.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/other/incomplete1.C	2005-08-13 11:35:25 +0200
+++ gcc/gcc/testsuite/g++.dg/other/incomplete1.C	2005-08-18 17:29:20 +0200
@@ -0,0 +1,7 @@
+// PR c++/23089
+// Origin: Flash Sheridan  <flash@pobox.com>
+// ICE on incomplete type
+// { dg-do compile }
+// { dg-options "-O" }
+
+void foo(struct A) {} // { dg-error "incomplete type|forward declaration" }
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]