[comp.lang.c++] Possible cfront v1.2 bug.

calder@uluru.UUCP (06/05/87)

I have had a few problems with pointers to member functions in 
version 1.2 of the C++ translator.  Specifically, there seem to
be bugs in using local variables of type "pointer-to-member-function",
especially if the class concerned has virtual member functions.

Here is a simple example.

	struct S {
	    virtual void f() { }
	} s;

	void (S::*p)() = &S::f;	    // works fine if p is global
	
	int main() {
	    (s.*p)();
	}

But now try making p local to main.

	struct S {
	    virtual void f() { }
	} s;
	
	int main() {
	    void (S::*p)() = &S::f; // "syntax error" if p is local
	    (s.*p)();
	}

OK then, why not make a global typedef and a local variable?

	struct S {
	    virtual void f() { }
	} s;
	
	typedef void (S::*pf)();
	
	int main() {
	    pf p = &S::f;
	    (s.*p)();
	}			    // "bus error (or something nasty...)"

Note that if S::f is not virtual, all is well. (Also note that this used to
work fine under version 1.1)

Is this a bug, or am I missing something?

Paul Calder (calder@uluru.stanford.edu)
Stanford University, Centre for Integrated Systems, Computer Systems Lab.