This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Pointers to overloaded functions


This is repost of yesterday's message, reformated (and after trying
again with a more recent egcs) with better indication of what's going
on.

gcc seems to be miss-resolving pointers to overloaded functions.  If I
reverse the two callback declarations in class foobar, all messages
dissappear, and the correct function is used.  I can't see it being
correct that the function selected is dependent on it's declaration
order; it never has before (this is the first time I tried this with
egcs, only gcc-2.7.2.1 and below and other C++ compilers).

[bcurrie@nzlc01 ~]
$ cat oload-bug.cc
void func(void (*)(void *, void *), void *);
void func(void (*)(void *), void *);
void foo(void (*)(void *), void *);

class foobar {
    static void callback(void *);
    void callback();
  public:
    foobar();
};

void foobar::callback()
{
}

void foobar::callback(void *obj)
{
    ((foobar*)obj)->callback();
}

foobar::foobar()
{
    func(callback,this);
    foo(callback,this);
}
[bcurrie@nzlc01 ~]
$ gcc -v
Reading specs from
/home/users/bcurrie/lib/gcc-lib/hppa1.1-stratus-sysv4/egcs-2.91.52/specs
gcc version egcs-2.91.52 19980802 (gcc2 ss-980609 experimental)
[bcurrie@nzlc01 ~]
$ gcc -Wall -Werror -O2 -S oload-bug.cc 
oload-bug.cc: In method `foobar::foobar()':
oload-bug.cc:23: no matching function for call to `func (void
(foobar::)(), foobar *)'
oload-bug.cc:1: candidates are: func(void (*)(void *, void *), void *)
oload-bug.cc:2:                 func(void (*)(void *), void *)
cc1plus: warnings being treated as errors
oload-bug.cc:24: warning: assuming & on `foobar::callback()'
oload-bug.cc:24: warning: converting from `void (foobar::*)()' to `void
(*)(void *)'

Bill
-- 
Leave others their otherness


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]