This is the mail archive of the gcc-bugs@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]

Re: Bug in cp/parse.y in 3.1 branch


On Tue, Apr 23, 2002 at 12:10:17PM -0700, David O'Brien wrote:
> > It is assigned into $3, not read.
> 
> So?  What is it being assigned into then?  There is no 3rd RHS rule in
>          nomods_initdcl0: notype_declarator maybeasm
> 
> Is this working around a bug in Bison, or utilizing a Bison extension?
> cc1plus built with a Byacc produced parse.c will not accept all valid C++
> code.

No, it is just setting things up as the C++ parser expects.
initdcl0_innards expects

{declmods,declspecs} {declarator,notype_declarator} maybeasm initdcl0_innards

on the stack.
Both initdcl0 and notype_inidcl0 comply to this, as they are:
initdcl0:
          declarator maybeasm initdcl0_innards
                {}
        ;

notype_initdcl0:
          notype_declarator maybeasm initdcl0_innards
                {}
        ;

and used in contexts like:
notype_initdecls:
          notype_initdcl0

template_datadef:
          declmods notype_initdecls ';'

But nomods_initdcl0 does not do this:

nomods_initdecls:
          nomods_initdcl0
template_datadef:
          nomods_initdecls ';'

so you end up with ??? notype_declarator maybeasm initdcl0_innards

on the stack, where ??? is unspecified, certainly not what initdcl0_innards
expects. If it is 0 and with lookups 0, then you're lucky, if not, you
loose. So what the code in nomods_initdcl0 does is to move the stack
to make room for the 0/0.

The following patch might work instead, though it is completely untested.
What should be tested is that e.g.:
template <typename T> struct foo {
  foo();
  operator bool() const;
};
template <typename T> foo<T>::operator bool() const { return 1; }
foo<int>::operator bool() const asm ("BOOLxx") __attribute__((unused));

is parsed the same way before and after the patch.

2002-04-24  Jakub Jelinek  <jakub@redhat.com>

	* parse.y (nomods_initdcl0_innards): New.
	(nomods_initdcl0): Use nomods_initdcl0_innards instead of
	hack plus initdcl0_innards.

--- gcc/cp/parse.y.jj	Tue Apr 23 19:47:28 2002
+++ gcc/cp/parse.y	Tue Apr 23 23:32:23 2002
@@ -2105,7 +2105,21 @@ initdcl0_innards:
 					$<ftype>-2.lookups, $1, 0);
 		  parse_end_decl (d, NULL_TREE, $<ttype>0); }
   	;
-  
+
+        /* This rule is identical to initdcl0_innards, just it doesn't
+	   use $-2 and uses NULL instead.  */
+nomods_initdcl0_innards:
+	  maybe_attribute '='
+		{ $<ttype>$ = parse_decl0 ($<ttype>-1, 0, 0, $1, 1); }
+          /* Note how the declaration of the variable is in effect
+	     while its init is parsed! */ 
+	  init
+		{ parse_end_decl ($<ttype>3, $4, $<ttype>0); }
+	| maybe_attribute
+		{ tree d = parse_decl0 ($<ttype>-1, 0, 0, $1, 0);
+		  parse_end_decl (d, NULL_TREE, $<ttype>0); }
+  	;
+
 initdcl0:
 	  declarator maybeasm initdcl0_innards
                 {}
@@ -2117,14 +2131,8 @@ notype_initdcl0:
         ;
   
 nomods_initdcl0:
-          notype_declarator maybeasm
-            { /* Set things up as initdcl0_innards expects.  */
-	      $<ttype>3 = $2;
-	      $2 = $1; 
-              $<ftype>1.t = NULL_TREE;
-	      $<ftype>1.lookups = NULL_TREE; }
-          initdcl0_innards 
-            {}
+          notype_declarator maybeasm nomods_initdcl0_innards
+		{}
 	| constructor_declarator maybeasm maybe_attribute
 		{ tree d = parse_decl0 ($1, NULL_TREE, NULL_TREE, $3, 0);
 		  parse_end_decl (d, NULL_TREE, $2); }


	Jakub


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