delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/29/00:34:37

From: scarlet AT mit DOT edu (Benjamin Sean Scarlet)
Subject: exception handling bug in b18 g++
29 Jul 1997 00:34:37 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <33DD8D20.42D26F97.cygnus.gnu-win32@mit.edu>
Reply-To: scarlet AT mit DOT edu
Mime-Version: 1.0
X-Mailer: Mozilla 4.01 [en] (WinNT; I)
Original-To: gnu-win32 Mailing List <gnu-win32 AT cygnus DOT com>
X-Priority: 3 (Normal)
Original-Sender: owner-gnu-win32 AT cygnus DOT com

I seem to have found some odd bug in exception handling: after
a catch block in a member function, the this pointer is corrupted:

--------------------------test.C------------------------------------
#include <iostream.h>

class X
{
  int x;
public:
  void foo();
};

void printit(void *p) 
{
  cerr << p << endl; 
}

void X::foo()
{
  printit(this);
  try
    { 
      printit(this);
      throw 1; 
    }
  catch(int)
    {
      printit(this); 
    }
  printit(this);
}

main()
{
  X x;
  x.foo();
}
----------------------------------------------------------------------
When I try this, I get:

bash$ g++ -fexceptions test.C -o test
bash$ ./test
0x241f464
0x241f464
0x241f464
0x40c0f8

As a side note, a possible quick fix is to turn on optimization:
bash$ g++ -O -fexceptions test.C -o test
bash$ ./test
0x241f464
0x241f464
0x241f464
0x241f464

	Benjamin Scarlet
	scarlet AT mit DOT edu

-----------------------------------------------------------------------
Configuration particulars:
Pentium II, Windows NT 4.0 (service pack 3)

An even further aside:  I don't know how extensive the Cygnus changes to
the g++ exception handling code are, so I figured it wouldn't hurt to
try this
program on a Linux box with vanilla gcc-2.7.2.1:  There I get no
problem.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019