possible namespace lookup bug

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Wed Oct 21 15:12:00 GMT 1998


> The program below gives a "parse" error apparently because it does not
> recognize the name "A".

Thanks for your bug report, I've added it as
g++.martin/lookup1.C. Here is a patch.

Martin

1998-10-21  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* parse.y (named_class_head): Push into class while parsing the
	base class list.
	* decl2.c (push_scope, pop_scope): New functions.
	* tree.h: Declare them.

Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.95
diff -u -r1.95 parse.y
--- parse.y	1998/10/18 03:10:53	1.95
+++ parse.y	1998/10/21 20:55:09
@@ -2235,14 +2235,19 @@
 		{ $$ = xref_tag (current_aggr, $1, 1); }
 	| named_class_head_sans_basetype_defn 
                 { $<ttype>$ = xref_tag (current_aggr, $1, 0); }
+          /* Class name is unqualified, so we look for base classes
+             in the current scope.  */
           maybe_base_class_list  %prec EMPTY
 		{ 
 		  $$ = $<ttype>2;
 		  if ($3)
                     xref_basetypes (current_aggr, $1, $<ttype>2, $3); 
 		}
-	| named_complex_class_head_sans_basetype maybe_base_class_list
+	| named_complex_class_head_sans_basetype 
+                { push_scope (CP_DECL_CONTEXT ($1)); }
+	  maybe_base_class_list
 		{ 
+                  pop_scope (CP_DECL_CONTEXT ($1));
 		  $$ = TREE_TYPE ($1);
 		  if (TREE_INT_CST_LOW (current_aggr) == union_type 
 		      && TREE_CODE ($$) != UNION_TYPE)
@@ -2250,10 +2255,10 @@
 		  else if (TREE_CODE ($$) == UNION_TYPE
 			   && TREE_INT_CST_LOW (current_aggr) != union_type)
 		    cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
-		  if ($2)
+		  if ($3)
 		    {
 		      maybe_process_partial_specialization ($$);
-		      xref_basetypes (current_aggr, $1, $$, $2); 
+		      xref_basetypes (current_aggr, $1, $$, $3); 
 		    }
 		}
 	;
Index: decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.147
diff -u -r1.147 decl2.c
--- decl2.c	1998/10/19 20:08:13	1.147
+++ decl2.c	1998/10/21 20:55:50
@@ -4330,6 +4353,30 @@
 check_decl_namespace ()
 {
   my_friendly_assert (decl_namespace_list == NULL_TREE, 980711);
+}
+
+/* Enter a class or namespace scope. */
+
+void
+push_scope (t)
+     tree t;
+{
+  if (TREE_CODE (t) == NAMESPACE_DECL)
+    push_decl_namespace (t);
+  else
+    pushclass (t, 2);
+}
+
+/* Leave scope pushed by push_scope. */
+
+void
+pop_scope (t)
+     tree t;
+{
+  if (TREE_CODE (t) == NAMESPACE_DECL)
+    pop_decl_namespace ();
+  else
+    popclass (1);
 }
 
 /* [basic.lookup.koenig] */
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.156
diff -u -r1.156 cp-tree.h
--- cp-tree.h	1998/10/19 20:08:11	1.156
+++ cp-tree.h	1998/10/21 21:34:13
@@ -2668,6 +2674,8 @@
 extern tree current_decl_namespace              PROTO((void));
 extern void push_decl_namespace                 PROTO((tree));
 extern void pop_decl_namespace                  PROTO((void));
+extern void push_scope				PROTO((tree));
+extern void pop_scope				PROTO((tree));
 extern void do_namespace_alias			PROTO((tree, tree));
 extern void do_toplevel_using_decl		PROTO((tree));
 extern void do_local_using_decl                 PROTO((tree));



More information about the Gcc-patches mailing list