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,committed] Fix PR c++/20646,ICE on "extern static" struct member


The testcase

  struct A
  {
    extern static int i;
  };

triggers an ICE on mainline and the 4.0 branch:

PR20646.cc:3: error: multiple storage classes in declaration of 'i'
PR20646.cc:3: internal compiler error: tree check: expected var_decl or function_decl or parm_decl, have field_decl in grokdeclarator, at cp/decl.c:8280

The ICE happens at the end of grokdeclarator in cp/decl.c:

    else if (storage_class == sc_extern)
      DECL_THIS_EXTERN (decl) = 1;

because DECL_THIS_EXTERN won't work with a field_decl.

Since the (sc_)extern is bogus anyway the patch below fixes the ICE
by clearing storage_class after the error message about multiple
storage classes.

Bootstrapped and regtested on i686-pc-linux-gnu.
Approved by Mark in PR 20646.
Committed to mainline and 4.0 branch.

Regards,
Volker


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

	PR c++/20646
	* decl.c (grokdeclarator): Reset storage_class after error.

===================================================================
--- gcc/gcc/cp/decl.c	1 Aug 2005 04:02:24 -0000	1.1416
+++ gcc/gcc/cp/decl.c	9 Aug 2005 13:10:55 -0000
@@ -7064,7 +7064,10 @@ grokdeclarator (const cp_declarator *dec
   /* Warn about storage classes that are invalid for certain
      kinds of declarations (parameters, typenames, etc.).  */
   if (declspecs->multiple_storage_classes_p)
-    error ("multiple storage classes in declaration of %qs", name);
+    {
+      error ("multiple storage classes in declaration of %qs", name);
+      storage_class = sc_none;
+    }
   else if (thread_p
 	   && ((storage_class
 		&& storage_class != sc_extern
===================================================================

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

	PR c++/20646
	* g++.dg/other/mult-stor1.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/other/mult-stor1.C	2005-08-08 15:18:00.296631696 +0200
+++ gcc/gcc/testsuite/g++.dg/other/mult-stor1.C	2005-08-10 02:06:32.000000000 +0200
@@ -0,0 +1,8 @@
+// PR c++/20646
+// Origin: Dan Rosen <dan.rosen@gmail.com>
+// { dg-do compile }
+
+struct A
+{
+  extern static int i;  // { dg-error "multiple storage classes" }
+};
===================================================================



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