public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch for templates in enums
@ 1997-09-08  2:23 Jody Goldberg
  1997-09-08  2:36 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jody Goldberg @ 1997-09-08  2:23 UTC (permalink / raw)
  To: jason; +Cc: egcs

Attched is a patch and test case to correct the expansion of templates
containing enums while in an enum declaration.  It should apply against
egcs-970907 in the gcc/cp directory.

enums were begin built using a global variable that was getting overwritten
when a template containing enums was expanded inside an enum decl.  The patch
saves and restores the current value of the global while doing template
expansion.  The value to use for the next enum also uses a global but does
not need to be saved since the template would only be expanded in a situation
where the value was being supplied.

Thanks

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jodyg@idt.net  | By definition all answers are replies. Unfortunately,
               | not all replies are answers.  -- JMS

--------------------------------------------------------------------------
*** ChangeLog	1997/09/06 07:17:37	1.1
--- ChangeLog	1997/09/06 08:42:15
***************
*** 9,11 ****
--- 9,18 ----
+ Sat Sep  6 09:11:38 1997  Jody Goldberg  <jodyg@idt.net>
+ 	* decl.c (current_local_enum): Remove static.
+ 	* pt.c (tsubst_enum): Save and restore value of current_local_enum
+ 	in case template is expanded in enum decl.
+ 	(instantiate_class_template) : Use new tsubst_enum signature.
+ 	(tsubst_expr): Likewise.
+ 
  Fri Sep  5 17:27:38 1997  Jason Merrill  <jason@yorick.cygnus.com>

  	* class.c (grow_method): Remove check for redeclaration.
*** pt.c	1997/09/06 07:17:19	1.2
--- pt.c	1997/09/06 08:40:43
***************
*** 76,82 ****
  static int list_eq PROTO((tree, tree));
  static tree get_class_bindings PROTO((tree, tree, tree));
  static tree coerce_template_parms PROTO((tree, tree, tree));
! static tree tsubst_enum	PROTO((tree, tree, int));
  static tree add_to_template_args PROTO((tree, tree));
  
  /* Restore the template parameter context. */
--- 76,82 ----
  static int list_eq PROTO((tree, tree));
  static tree get_class_bindings PROTO((tree, tree, tree));
  static tree coerce_template_parms PROTO((tree, tree, tree));
! static tree tsubst_enum	PROTO((tree, tree, int, tree *));
  static tree add_to_template_args PROTO((tree, tree));
  
  /* Restore the template parameter context. */
***************
*** 1432,1440 ****
        if (TREE_CODE (tag) == ENUMERAL_TYPE)
  	{
  	  tree e, newtag = tsubst_enum (tag, args, 
! 					TREE_VEC_LENGTH (args));
  
- 	  *field_chain = grok_enum_decls (newtag, NULL_TREE);
  	  while (*field_chain)
  	    {
  	      DECL_FIELD_CONTEXT (*field_chain) = type;
--- 1432,1439 ----
        if (TREE_CODE (tag) == ENUMERAL_TYPE)
  	{
  	  tree e, newtag = tsubst_enum (tag, args, 
! 					TREE_VEC_LENGTH (args), field_chain);
  
  	  while (*field_chain)
  	    {
  	      DECL_FIELD_CONTEXT (*field_chain) = type;
***************
*** 2832,2838 ****
        lineno = TREE_COMPLEXITY (t);
        t = TREE_TYPE (t);
        if (TREE_CODE (t) == ENUMERAL_TYPE)
! 	tsubst_enum (t, args, nargs);
        break;
  
      default:
--- 2831,2837 ----
        lineno = TREE_COMPLEXITY (t);
        t = TREE_TYPE (t);
        if (TREE_CODE (t) == ENUMERAL_TYPE)
! 	tsubst_enum (t, args, nargs, NULL);
        break;
  
      default:
***************
*** 4060,4069 ****
     tsubst_expr.  */
  
  static tree
! tsubst_enum (tag, args, nargs)
       tree tag, args;
       int nargs;
  {
    tree newtag = start_enum (TYPE_IDENTIFIER (tag));
    tree e, values = NULL_TREE;
  
--- 4059,4072 ----
     tsubst_expr.  */
  
  static tree
! tsubst_enum (tag, args, nargs, field_chain)
       tree tag, args;
       int nargs;
+      tree * field_chain;
  {
+   extern tree current_local_enum;
+   tree prev_local_enum = current_local_enum;
+ 
    tree newtag = start_enum (TYPE_IDENTIFIER (tag));
    tree e, values = NULL_TREE;
  
***************
*** 4077,4082 ****
--- 4080,4090 ----
      }
  
    finish_enum (newtag, values);
+ 
+   if (NULL != field_chain)
+     *field_chain = grok_enum_decls (newtag, NULL_TREE);
+ 
+   current_local_enum = prev_local_enum;
  
    return newtag;
  }
*** decl.c	1997/09/06 08:26:13	1.2
--- decl.c	1997/09/06 08:40:33
***************
*** 10797,10803 ****
  }
    
  \f
! static tree current_local_enum = NULL_TREE;
  
  /* Begin compiling the definition of an enumeration type.
     NAME is its name (or null if anonymous).
--- 10797,10803 ----
  }
    
  \f
! tree current_local_enum = NULL_TREE;
  
  /* Begin compiling the definition of an enumeration type.
     NAME is its name (or null if anonymous).
*** ../testsuite/g++.old-deja/g++.pt/enum.C	1997/09/06 08:48:40	1.1
--- ../testsuite/g++.old-deja/g++.pt/enum.C	1997/09/06 08:49:18
***************
*** 0 ****
--- 1,18 ----
+ // Build don't link: 
+ // GROUPS passed enums
+ template<class T>
+ struct templ
+ {
+     enum { val = 0 };
+ };
+ struct Foo
+ {
+     enum {
+ 	bar = 0,
+ 	len = templ<int>::val
+     };
+ };
+ void func()
+ {
+     int s = Foo::bar;	// Ensure that expansion of templ did not erase bar
+ }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Patch for templates in enums
  1997-09-08  2:23 Patch for templates in enums Jody Goldberg
@ 1997-09-08  2:36 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 1997-09-08  2:36 UTC (permalink / raw)
  To: jodyg; +Cc: egcs

Thanks, I put this in.  For future reference, ChangeLog entries should be
submitted as text, not as part of the patch; they don't apply correctly if
there have been any changes since you made the diff.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-09-08  2:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-08  2:23 Patch for templates in enums Jody Goldberg
1997-09-08  2:36 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).