Patch for pointer-to-enum problem

Mark Mitchell mmitchell@usa.net
Wed Jan 28 07:03:00 GMT 1998


Here's a better (correct, I hope) version of the patch I sent earlier
for code like this:

    struct A
    {
      enum { a = 3}* p;
      int f() { return (int) a; }
    };

where g++ pretended not to have heard of `a'.

-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu

Wed Jan 28 07:00:37 1998  Mark Mitchell  <mmitchell@usa.net>

	* cp-tree.h (grok_enum_decls): Remove type parameter.
	* decl.c (grok_enum_decls): Likewise.
	* decl2.c (grok_x_components): Call grok_enum_decls
	unconditionally, since it will do nothing if there is no
	current_local_enum.  Use the new calling sequence.
	* pt.c (tsubst_enum): Use the new calling sequence for
	grok_enum_decls. 
	
Index: gcc/cp/cp-tree.h
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.10
diff -c -p -r1.10 cp-tree.h
*** cp-tree.h	1998/01/28 01:32:40	1.10
--- cp-tree.h	1998/01/28 07:50:18
*************** extern void xref_basetypes			PROTO((tree
*** 2099,2105 ****
  extern tree start_enum				PROTO((tree));
  extern tree finish_enum				PROTO((tree, tree));
  extern tree build_enumerator			PROTO((tree, tree));
! extern tree grok_enum_decls			PROTO((tree, tree));
  extern int start_function			PROTO((tree, tree, tree, int));
  extern void expand_start_early_try_stmts	PROTO((void));
  extern void store_parm_decls			PROTO((void));
--- 2099,2105 ----
  extern tree start_enum				PROTO((tree));
  extern tree finish_enum				PROTO((tree, tree));
  extern tree build_enumerator			PROTO((tree, tree));
! extern tree grok_enum_decls			PROTO((tree));
  extern int start_function			PROTO((tree, tree, tree, int));
  extern void expand_start_early_try_stmts	PROTO((void));
  extern void store_parm_decls			PROTO((void));
Index: gcc/cp/decl.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/decl.c,v
retrieving revision 1.18
diff -c -p -r1.18 decl.c
*** decl.c	1998/01/28 07:36:37	1.18
--- decl.c	1998/01/28 07:50:10
*************** build_enumerator (name, value)
*** 11402,11409 ****
  }
  
  tree
! grok_enum_decls (type, decl)
!      tree type, decl;
  {
    tree d = current_local_enum;
    
--- 11402,11409 ----
  }
  
  tree
! grok_enum_decls (decl)
!      tree decl;
  {
    tree d = current_local_enum;
    
*************** grok_enum_decls (type, decl)
*** 11412,11418 ****
    
    while (1)
      {
-       TREE_TYPE (d) = type;
        if (TREE_CHAIN (d) == NULL_TREE)
  	{
  	  TREE_CHAIN (d) = decl;
--- 11412,11417 ----
Index: gcc/cp/decl2.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/decl2.c,v
retrieving revision 1.6
diff -c -p -r1.6 decl2.c
*** decl2.c	1998/01/28 01:32:44	1.6
--- decl2.c	1998/01/28 07:51:51
*************** grok_x_components (specs, components)
*** 916,922 ****
  		  break;
  	    }
  	  else if (TREE_CODE (t) == ENUMERAL_TYPE)
! 	    x = grok_enum_decls (t, NULL_TREE);
  	  else
  	    x = NULL_TREE;
  	  return x;
--- 916,922 ----
  		  break;
  	    }
  	  else if (TREE_CODE (t) == ENUMERAL_TYPE)
! 	    x = grok_enum_decls (NULL_TREE);
  	  else
  	    x = NULL_TREE;
  	  return x;
*************** grok_x_components (specs, components)
*** 929,941 ****
  	}
      }
    else
!     {
!       t = TREE_TYPE (components);
!       if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
! 	return grok_enum_decls (t, components);
!       else
! 	return components;
!     }
  }
  
  /* Classes overload their constituent function names automatically.
--- 929,940 ----
  	}
      }
    else
!     /* There may or may not be any enum decls to grok, but
!        grok_enum_decls will just return components, if there aren't
!        any.  We used to try to figure out whether or not there were
!        any enum decls based on the type of components, but that's too
!        hard; it might be something like `enum { a } *p;'.  */
!     return grok_enum_decls (components);
  }
  
  /* Classes overload their constituent function names automatically.
Index: gcc/cp/pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.16
diff -c -p -r1.16 pt.c
*** pt.c	1998/01/28 06:33:31	1.16
--- pt.c	1998/01/28 07:50:25
*************** tsubst_enum (tag, args, nargs, field_cha
*** 5881,5887 ****
    finish_enum (newtag, values);
  
    if (NULL != field_chain)
!     *field_chain = grok_enum_decls (newtag, NULL_TREE);
  
    current_local_enum = prev_local_enum;
  
--- 5881,5887 ----
    finish_enum (newtag, values);
  
    if (NULL != field_chain)
!     *field_chain = grok_enum_decls (NULL_TREE);
  
    current_local_enum = prev_local_enum;
  
Index: gcc/testsuite/g++.old-deja/g++.other/enum1.C
===================================================================
RCS file: enum1.C
diff -N enum1.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- /tmp/cvs03798aaa	Wed Jan 28 06:59:04 1998
***************
*** 0 ****
--- 1,15 ----
+ extern "C" void abort();
+ 
+ struct A
+ {
+   enum { a = 3}* p;
+   int f() { return (int) a; }
+ };
+ 
+ int main()
+ {
+   A a;
+ 
+   if (a.f() != 3)
+     abort();
+ }



More information about the Gcc-bugs mailing list