C++ PATCH for templates/qualified-name handling

mitchell@codesourcery.com mitchell@codesourcery.com
Sun May 16 23:48:00 GMT 1999


Here's a simple patch to handle the test-case below.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-05-16  Mark Mitchell  <mark@codesourcery.com>

	* decl2.c (build_expr_from_tree): Handle COMPONENT_REFs that
	indicate a reference to a field that is a qualified name.

Index: testsuite/g++.old-deja/g++.pt/lookup9.C
===================================================================
RCS file: lookup9.C
diff -N lookup9.C
--- /dev/null	Sat Dec  5 20:30:03 1998
+++ lookup9.C	Sun May 16 23:40:41 1999
@@ -0,0 +1,16 @@
+// Build don't link:
+// Origin: "Artem Hodyush" <artem@duma.gov.ru>
+
+struct B { int m; };
+
+template< class T >
+void
+q( T& t ) {
+  t.T::m=1;
+}
+
+void f() {
+  B b;
+  b.B::m=1;
+  q( b );
+}
Index: cp/decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.214
diff -u -p -r1.214 decl2.c
--- decl2.c	1999/05/10 12:12:50	1.214
+++ decl2.c	1999/05/17 06:40:44
@@ -4056,10 +4056,22 @@ build_expr_from_tree (t)
       }
 
     case COMPONENT_REF:
-      return build_x_component_ref
-	(build_expr_from_tree (TREE_OPERAND (t, 0)),
-	 TREE_OPERAND (t, 1), NULL_TREE, 1);
-      
+      {
+	tree object = build_expr_from_tree (TREE_OPERAND (t, 0));
+	tree field = TREE_OPERAND (t, 1);
+	
+	/* We use a COMPONENT_REF to indicate things of the form `x.b'
+	   and `x.A::b'.  We must distinguish between those cases
+	   here.  */
+	if (TREE_CODE (field) == SCOPE_REF)
+	  return build_object_ref (object, 
+				   TREE_OPERAND (field, 0),
+				   TREE_OPERAND (field, 1));
+	else
+	  return build_x_component_ref (object, field,
+					NULL_TREE, 1);
+      }
+
     case THROW_EXPR:
       return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
 


More information about the Gcc-patches mailing list