Internal compiler error

Per Boussard per@era-t.ericsson.se
Wed Feb 17 14:03:00 GMT 1999


Hello heroes,

I got a dreaded 'Internal compiler error' while doing something probably
pretty stupid with egcs-1.0.3 (it's what comes with redhat-5.2). If this
is a clear you-got-what-you-deserve-and-I-don't-wanna-hear-'bout-it
category problem, feel free to feed /dev/null with this email.

If you don't... I tried to do something which is pretty straight-forward
in c, but not quite so much so in c++ -- to use a function-pointer as a
'pluggable function' entry. I'm sure I did it wrong too, and I know now
that it can't really be done easily, but...

Here's the c-example to show you what I want to do..
----
#include <unistd.h>
#include <stdio.h>

void (*f)();

void f1(){fprintf(stderr,"Running f1\n");}

void f2(){fprintf(stderr,"Running f2\n");}

void Register(void(*g)()){f=g;}

int main(int argc, char **argv)
{
	Register(f1);
	f();
	Register(f2);
	f();
}
-----
running this yields
%./c-example
Running f1
Running f2

Now, writing (well.. trying to) the same/similar thing in c++, this
('this' contains the same letter as 'shit') happens.
%make
g++ -o one One.cc
One.cc: In method `void One::callHandler()':
One.cc:53: Internal compiler error.
One.cc:53: Please submit a full bug report to `egcs-bugs@cygnus.com'.
make: *** [all] Error 1
%g++ --version
egcs-2.90.29 980515 (egcs-1.0.3 release)

To give you the whole story...
%cat One.cc
#include <unistd.h>
#include <stdio.h>

// Handler is just something we cast to.
class Handler
{
};

class One: public Handler
{
public:
	One();
	void doRegister(void(Handler::*)(void));
	void callHandler();
	void handler1(void);
	void handler2(void);
	void (Handler::*theFunction)();
};

int main(int argc, char **argv)
{
	One *one;

	one = new One();
	if (one == NULL)
	{
		fprintf(stderr,"Can't create One\n");
		exit(1);
	}
	one->doRegister((void(Handler::*)())&one->handler1);
	one->callHandler();
	one->doRegister((void(Handler::*)())&one->handler2);
	one->callHandler();
}

One::One(){}
void One::doRegister(void(Handler::*f)(void))
{
	theFunction = f;
}
void One::handler1()
{
	fprintf(stderr,"This is handler 1\n");
}

void One::handler2()
{
	fprintf(stderr,"This is handler 2\n");
}

void One::callHandler()
{
	this->theFunction();
}
-----

Now.. I know there is at least 1.1.1 out, but it's 11 meg, which is
forever over 28k8, and I doubt that I'll get around to updating any time
soon unless I have a c-problem (I really hate to code in c++, and it
shows), but I figured you may want to look at this since it's an internal
problem. There's no doubt that the shere intensity of hidiousness of my
code triggered this, but it's non the less advertised as an internal
problem, so...

Best regards, and thanks
//Per

PS: I promise to stay away from c++, but if this leads anywhere I'd be
interested to hear.



More information about the Gcc-bugs mailing list