Internal compiler error

I found a gcc bug again!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Example
{
protected:
  typedef void(Example::*FP)(int);

  static void fs();
         void fn(int x);

  virtual FP get_fn();


};

void Example::fs()
{
    Example *ex;
    // ...
    ex->get_fn()->*(1); // here!
}

Example::FP Example::get_fn()
{
    return &Example::fn;
}


void fn()
{

}

internal compiler error: in cp_build_indirect_ref, at cp/typeck.c:2779


gcc-mingw version 4.5.0

This is the second time I get this error message; last time this error message simply disappeared after some time, but this time I was able to isolate the error.

Am I the only one who is getting this strange error? And where the "cp/typechk.cpp" file is?
1
2
3
4
Example::FP Example::get_fn()
{
    return &Example::fn;
}
Shouldn't that be prepended by a void?

Also, a typedef isn't to be treated as a preprocessor directive. A typedef is for types, virtual FP get_fn(); should be interpreted as creating a virtual method pointer (!) as a member.
Last edited on
I'm pretty sure you're calling the function wrong. Maybe you're not supposed to get an internal compiler error, but I would imagine you would get some kind of error.

I think the right way to do it is like this:

1
2
3
4
5
6
7
8
// ex->get_fn()->*(1); // bad

// good:
(ex->*get_fn())(1);

// also good:
FP fp = get_fn();
(ex->*fp)(1);


Note that the parenethesis there are not superfluous. They are important.

Also note that I didn't actually test this so I might be wrong =x

Try it out and see.


Anyway this is one of the many reasons I avoid function pointers like the plague.
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.5

And the one below it if you want a reference.
Topic archived. No new replies allowed.