home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2099 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.9 KB  |  130 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 overloaded postfix increment decrement bug in gcc2.3.3
  5. Message-ID: <9212300056.AA06430@kelvin.seas.Virginia.EDU>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 29 Dec 1992 14:56:25 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 117
  12.  
  13. A patch that fixes the overloaded postfix increment decrement
  14. bug in gcc 2.3.3 follows an example:
  15.  
  16. The correct output should be
  17. ++X 1
  18. X++ 1 0
  19. ++X 3
  20. X++ 3 1
  21. Y++ 100 0
  22. ++Y 102
  23. ++Y 103
  24. Y++ 103 10
  25.  
  26.  
  27. #include <iostream.h>
  28.  
  29. class X {
  30.     int i;
  31. public:
  32.     X (): i(0) {}
  33.  
  34.     X& operator ++ ()
  35.      { ++i; cout << "++X " << i << endl; return *this; }
  36.     X& operator ++ (int j=2)
  37.     { cout << "X++ " << i << ' ' << j << endl; i++; return *this; }
  38. };
  39.  
  40. class Y {
  41.     int i;
  42. public:
  43.     Y (): i(100) {}
  44.  
  45.     friend Y& operator ++ (Y& y)
  46.      { ++y.i; cout << "++Y " << y.i << endl; return y; }
  47.     friend Y& operator ++ (Y& y, int j)
  48.     { cout << "Y++ " << y.i << ' ' << j << endl; ++y.i; return y; }
  49. };
  50.  
  51. main()
  52. {
  53.     X x;
  54.     ++x;
  55.     x++;
  56.  
  57.     x.operator ++ ();
  58.     x.operator ++ (1);
  59.  
  60.     Y y;
  61.     y++;
  62.     ++y;
  63.  
  64.     operator ++ (y);
  65.     operator ++ (y, 10);
  66. }
  67.  
  68. ChangeLog:
  69.  
  70. Tue Dec 29 19:36:26 EST 1992 Gnanasekaran Swaminathan (gs4t@virginia.edu)
  71.  
  72.     * cp-method.c (build_opfncall): If type of xarg1 is an aggregate,
  73.     then set xarg2 to integer_zero_node for postfix increment and 
  74.     decrement expressions as required by ARM p338-339.
  75.  
  76. *** cp-method.c.orig    Tue Dec 29 18:55:41 1992
  77. --- cp-method.c    Tue Dec 29 19:11:18 1992
  78. ***************
  79. *** 2096,2113 ****
  80.     switch (code)
  81.       {
  82. !     case PREINCREMENT_EXPR:
  83. !       code = POSTINCREMENT_EXPR;
  84. !       binary_is_unary = 1;
  85. !       try_second = 0;
  86. !       break;
  87.       case POSTDECREMENT_EXPR:
  88. -       code = PREDECREMENT_EXPR;
  89. -       binary_is_unary = 1;
  90. -       try_second = 0;
  91. -       break;
  92.       case PREDECREMENT_EXPR:
  93. !     case POSTINCREMENT_EXPR:
  94.       case COMPONENT_REF:
  95.         binary_is_unary = 1;
  96. --- 2096,2103 ----
  97.     switch (code)
  98.       {
  99. !     case POSTINCREMENT_EXPR:
  100.       case POSTDECREMENT_EXPR:
  101.       case PREDECREMENT_EXPR:
  102. !     case PREINCREMENT_EXPR:
  103.       case COMPONENT_REF:
  104.         binary_is_unary = 1;
  105. ***************
  106. *** 2274,2280 ****
  107.        argument.  */
  108.   
  109. !   if (IS_AGGR_TYPE (type1))
  110. !     fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
  111.     if (fields1 == NULL_TREE && global_fn == NULL_TREE)
  112.       return rval;
  113. --- 2264,2275 ----
  114.        argument.  */
  115.   
  116. !   if (IS_AGGR_TYPE (type1)) {
  117. !       fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
  118. !       if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) {
  119. !       xarg2 = integer_zero_node;
  120. !       binary_is_unary = 0;
  121. !       }
  122. !   }
  123. !       
  124.     if (fields1 == NULL_TREE && global_fn == NULL_TREE)
  125.       return rval;
  126.  
  127.