home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2105 < prev    next >
Encoding:
Text File  |  1993-01-01  |  4.3 KB  |  163 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!kelvin.seas.virginia.edu!gs4t
  3. From: gs4t@kelvin.seas.virginia.edu (Gnanasekaran  Swaminathan)
  4. Subject: Fix for class local enum bug
  5. Message-ID: <9212310357.AA48953@kelvin.seas.Virginia.EDU>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Wed, 30 Dec 1992 17:57:38 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 150
  12.  
  13. A patch that fixes the following two bugs in gcc-2.3.3 follows:
  14.  
  15. Bug1: gcc2.3.3 does not let member functions of nested classes
  16.       to define its own local classes and enum.
  17.         
  18. Bug2: gcc2.3.3 does not define a class local enum as soon as it is
  19.       supposed to be defined. See ARM p114 for details.
  20.      
  21. example:
  22. struct A {
  23.   struct B {
  24.     int f() {
  25.       enum { a=1, b=3 }; // Bug1. fails without the patch
  26.       struct C { int j; }; // Bug1. fails without the patch
  27.       return a*b;
  28.     }
  29.   };
  30.   enum { a = 3, b = a*4 }; // Bug2. fails without the patch
  31. };
  32.  
  33. ChangeLog:
  34.  
  35. Wed Dec 30 22:22:32 EST 1992 Gnanasekaran Swaminathan (gs4t@virginia.edu)
  36.  
  37.     * cp-decl.c (lookup_nested_type): Next context is RECORD_TYPE
  38.     in case of local classes in member functions of nested classes.
  39.     So, get the type decl from TREE_CHAIN (context) as the next context.
  40.     (classlocal_enum_decls): A new static variable is introduced.
  41.     (start_enum): Tag of enumtype is made addressable as soon as one is
  42.     pushed. (build_enumerator): A class local enumerator is declared
  43.     as soon as the name and its initializer are seen (cf. ARM p114).
  44.     (grok_enum_decls): Cleaned up as most of its code are moved to
  45.     build_enumerator now.
  46.  
  47. *** cp-decl.c.orig    Mon Dec 28 18:33:18 1992
  48. --- cp-decl.c    Wed Dec 30 22:08:12 1992
  49. ***************
  50. *** 3753,3756 ****
  51. --- 3753,3758 ----
  52.             return TREE_VALUE (match);
  53.           context = DECL_CONTEXT (context);
  54. +         if (context && TREE_CODE (context) == RECORD_TYPE)
  55. +         context = TREE_CHAIN (context);
  56.         }
  57.         break;
  58. ***************
  59. *** 9390,9393 ****
  60. --- 9392,9397 ----
  61.   }
  62.   
  63. + static tree classlocal_enum_decls = NULL_TREE;
  64.   /* Begin compiling the definition of an enumeration type.
  65.      NAME is its name (or null if anonymous).
  66. ***************
  67. *** 9415,9420 ****
  68. --- 9419,9429 ----
  69.         enumtype = make_node (ENUMERAL_TYPE);
  70.         pushtag (name, enumtype);
  71. +       if (current_class_type != NULL_TREE)
  72. +       TREE_ADDRESSABLE (b->tags) = 1;
  73.       }
  74.   
  75. +   classlocal_enum_decls = NULL_TREE;
  76.     if (TYPE_VALUES (enumtype) != 0)
  77.       {
  78. ***************
  79. *** 9588,9591 ****
  80. --- 9597,9614 ----
  81.       }
  82.   
  83. +   if (current_class_type != NULL_TREE)
  84. +     {
  85. +       /* class local enum declaration */
  86. +       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
  87. +       DECL_INITIAL (decl) = value;
  88. +       TREE_READONLY (decl) = 1;
  89. +       pushdecl_class_level (decl);
  90. +       /* chain the decl in the tree classlocal_enum_decls
  91. +      See grok_enum_decls () where it is used and reset. */
  92. +       TREE_CHAIN (decl) = classlocal_enum_decls;
  93. +       classlocal_enum_decls = decl;
  94. +     }
  95.     /* Set basis for default for next value.  */
  96.     enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  97. ***************
  98. *** 9601,9634 ****
  99.        tree type, decl;
  100.   {
  101. !   struct binding_level *b = class_binding_level;
  102. !   tree tag = NULL_TREE;
  103. !   tree values;
  104.   
  105. !   while (b)
  106. !     {
  107. !       tag = value_member (type, b->tags);
  108. !       if (tag)
  109. !     break;
  110. !       b = b->level_chain;
  111. !     }
  112.   
  113. !   if (b == 0 || (b != class_binding_level) || TREE_ADDRESSABLE (tag))
  114.       return decl;
  115. !   else
  116. !     TREE_ADDRESSABLE (tag) = 1;
  117. !   values = TYPE_VALUES (type);
  118. !   while (values)
  119.       {
  120. !       /* Create a declaration for the enum value name.  */
  121. !       tree next = build_lang_field_decl (CONST_DECL, TREE_PURPOSE (values), type);
  122. !       TREE_READONLY (next) = 1;
  123. !       DECL_INITIAL (next) = TREE_VALUE (values);
  124. !       TREE_CHAIN (next) = decl;
  125. !       decl = next;
  126. !       pushdecl_class_level (decl);
  127. !       values = TREE_CHAIN (values);
  128.       }
  129. !   return decl;
  130.   }
  131.   
  132. --- 9624,9646 ----
  133.        tree type, decl;
  134.   {
  135. !   tree d, ret;
  136.   
  137. !   d = ret = classlocal_enum_decls;
  138. !   classlocal_enum_decls = NULL_TREE;
  139.   
  140. !   if (d == 0)
  141.       return decl;
  142. !   
  143. !   for (;;)
  144.       {
  145. !       TREE_TYPE (d) = type;
  146. !       if (TREE_CHAIN (d) == NULL_TREE)
  147. !     {
  148. !       TREE_CHAIN (d) = decl;
  149. !       break;
  150. !         }
  151. !       d = TREE_CHAIN (d);
  152.       }
  153. !   return ret;
  154.   }
  155.   
  156.  
  157.