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

Re: almost there w/ the rewrite testin' ... [Re: template enum buglet?]



Brendan --

  OK, here's the fix.  Some code I wrote in pt.c sensibly assumed a
correct DECL_CONTEXT for the CONST_DECLs, but it was not being set
up.  (Another side-effect of this fix, by the way, is that the names
of enumeration constants in class/function scope are now printed
correctly in error messages; previously they were given as unqualified
names.)

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-08-27  Mark Mitchell  <mark@markmitchell.com>

	* decl.c (build_enumerator): Set DECL_CONTEXT for the
	CONST_DECLs. 

Index: testsuite/g++.old-deja/g++.pt/enum9.C
===================================================================
RCS file: enum9.C
diff -N enum9.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- enum9.C	Thu Aug 27 00:08:40 1998
***************
*** 0 ****
--- 1,13 ----
+ // Build don't link:
+ 
+ template <typename _CharT>
+ class _Format_cache
+ {
+ public:  
+   enum {   
+     _S_digits,   _S_digits_end = _S_digits+10,
+     _S_xdigits = _S_digits_end,
+   };
+ };
+ 
+ template class _Format_cache<int>;
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.193
diff -c -p -r1.193 decl.c
*** decl.c	1998/08/26 13:55:42	1.193
--- decl.c	1998/08/27 07:09:46
*************** build_enumerator (name, value)
*** 11994,11999 ****
--- 11994,12000 ----
       tree name, value;
  {
    tree decl, result;
+   tree context;
  
    /* Remove no-op casts from the value.  */
    if (value)
*************** build_enumerator (name, value)
*** 12042,12071 ****
     value = copy_node (value);
  
    /* C++ associates enums with global, function, or class declarations.  */
  
!   decl = current_scope ();
!   if (decl && decl == current_class_type)
!     {
!       /* This enum declaration is local to the class, so we must put
! 	 it in that class's list of decls.  */
!       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
!       DECL_INITIAL (decl) = value;
!       TREE_READONLY (decl) = 1;
!       pushdecl_class_level (decl);
!       TREE_CHAIN (decl) = current_local_enum;
!       current_local_enum = decl;
!     }
!   else
!     {
!       /* It's a global enum, or it's local to a function.  (Note local to
! 	 a function could mean local to a class method.  */
!       decl = build_decl (CONST_DECL, name, integer_type_node);
!       DECL_INITIAL (decl) = value;
!       TREE_READONLY (decl) = 1;
! 
!       pushdecl (decl);
!       GNU_xref_decl (current_function_decl, decl);
!     }
  
   if (! processing_template_decl)
     {
--- 12043,12073 ----
     value = copy_node (value);
  
    /* C++ associates enums with global, function, or class declarations.  */
+  
+  context = current_scope ();
+  if (context && context == current_class_type)
+    /* This enum declaration is local to the class.  */
+    decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
+  else
+    /* It's a global enum, or it's local to a function.  (Note local to
+       a function could mean local to a class method.  */
+    decl = build_decl (CONST_DECL, name, integer_type_node);
+ 
+  DECL_CONTEXT (decl) = FROB_CONTEXT (context);
+  DECL_INITIAL (decl) = value;
+  TREE_READONLY (decl) = 1;
  
!  if (context && context == current_class_type)
!    {
!      pushdecl_class_level (decl);
!      TREE_CHAIN (decl) = current_local_enum;
!      current_local_enum = decl;
!    }
!  else
!    {
!      pushdecl (decl);
!      GNU_xref_decl (current_function_decl, decl);
!    }
  
   if (! processing_template_decl)
     {


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