🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1189

Fix for overloaded postfix increment decrement bug in gcc2.3.3

#1189
From: Gnanasekaran Swaminathan
Date: Tue, 29 Dec 1992 14:56
116 lines
3049 bytes
A patch that fixes the overloaded postfix increment decrement
bug in gcc 2.3.3 follows an example:

The correct output should be
++X 1
X++ 1 0
++X 3
X++ 3 1
Y++ 100 0
++Y 102
++Y 103
Y++ 103 10


#include <iostream.h>

class X {
    int i;
public:
    X (): i(0) {}

    X& operator ++ ()
 	{ ++i; cout << "++X " << i << endl; return *this; }
    X& operator ++ (int j=2)
	{ cout << "X++ " << i << ' ' << j << endl; i++; return *this; }
};

class Y {
    int i;
public:
    Y (): i(100) {}

    friend Y& operator ++ (Y& y)
 	{ ++y.i; cout << "++Y " << y.i << endl; return y; }
    friend Y& operator ++ (Y& y, int j)
	{ cout << "Y++ " << y.i << ' ' << j << endl; ++y.i; return y; }
};

main()
{
    X x;
    ++x;
    x++;

    x.operator ++ ();
    x.operator ++ (1);

    Y y;
    y++;
    ++y;

    operator ++ (y);
    operator ++ (y, 10);
}

ChangeLog:

Tue Dec 29 19:36:26 EST 1992 Gnanasekaran Swaminathan (gs4t@virginia.edu)

	* cp-method.c (build_opfncall): If type of xarg1 is an aggregate,
	then set xarg2 to integer_zero_node for postfix increment and 
	decrement expressions as required by ARM p338-339.

*** cp-method.c.orig	Tue Dec 29 18:55:41 1992
--- cp-method.c	Tue Dec 29 19:11:18 1992
***************
*** 2096,2113 ****
    switch (code)
      {
!     case PREINCREMENT_EXPR:
!       code = POSTINCREMENT_EXPR;
!       binary_is_unary = 1;
!       try_second = 0;
!       break;
! 
      case POSTDECREMENT_EXPR:
-       code = PREDECREMENT_EXPR;
-       binary_is_unary = 1;
-       try_second = 0;
-       break;
- 
      case PREDECREMENT_EXPR:
!     case POSTINCREMENT_EXPR:
      case COMPONENT_REF:
        binary_is_unary = 1;
--- 2096,2103 ----
    switch (code)
      {
!     case POSTINCREMENT_EXPR:
      case POSTDECREMENT_EXPR:
      case PREDECREMENT_EXPR:
!     case PREINCREMENT_EXPR:
      case COMPONENT_REF:
        binary_is_unary = 1;
***************
*** 2274,2280 ****
       argument.  */
  
!   if (IS_AGGR_TYPE (type1))
!     fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
! 
    if (fields1 == NULL_TREE && global_fn == NULL_TREE)
      return rval;
--- 2264,2275 ----
       argument.  */
  
!   if (IS_AGGR_TYPE (type1)) {
!       fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
!       if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) {
! 	  xarg2 = integer_zero_node;
! 	  binary_is_unary = 0;
!       }
!   }
! 	  
    if (fields1 == NULL_TREE && global_fn == NULL_TREE)
      return rval;
Technical Details
Message-ID: <9212300056.AA06430@kelvin.seas.Virginia.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!kelvin.seas.virginia.edu!gs4t

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!kelvin.seas.virginia.edu!gs4t
From: gs4t@kelvin.seas.virginia.edu (Gnanasekaran  Swaminathan)
Subject: Fix for overloaded postfix increment decrement bug in gcc2.3.3
Message-ID: <9212300056.AA06430@kelvin.seas.Virginia.EDU>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 29 Dec 1992 14:56:25 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 117