This is the mail archive of the gcc@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]

bug in release-1.0 with respect to method pointers?



Hello.  I'm trying to compile a large project I'm working on with
egcs-1.0.  I'm immediatley having compilation problems.  Here is some code
that precisely illustrates the problem:

[ begin included source ]

#include <iostream.h>

class abstractBase {
public:
  abstractBase(){}
  ~abstractBase(){}
  
  virtual int returnInt(){
    return -1;
  }
};

class commonAbstract : abstractBase {
public:
  commonAbstract(){}
  ~commonAbstract(){}
  
  virtual int returnInt(){
    return -1;
  }
};

class derived1 : public commonAbstract {
public:
  derived1(){}
  ~derived1(){}

  int returnInt(){
    return 1;
  }
};

class derived2 : public commonAbstract {
public:
  derived2(){}
  ~derived2(){}
  
};

class unrelated {
public:
  unrelated(){}
  ~unrelated(){}
  
  void printResult(commonAbstract *callOn, int(commonAbstract::*memberFunction)() ){
    cout << (callOn->*memberFunction)() << endl;
  }
  
};

int 
main( int argc, char *argv[] ){
  commonAbstract *ca1, *ca2;
  unrelated *u;

  u = new unrelated();
  ca1 = new derived1();
  ca2 = new derived2();

  cout << "Testing on a derived1" << endl;
  u->printResult( ca1, commonAbstract::returnInt );

  cout << "Testing on a derived2" << endl;
  u->printResult( ca2, commonAbstract::returnInt );
}

[ end included source ]

This code compiles and behaves as expected with g++-2.7.2.3 and SunPro
4.2.

(Here is the output:)
Testing on a derived1
1
Testing on a derived2
-1

With egcs-1.0 I get:
bug.cc: In function `int main(int, char **)':
bug.cc:61: no matching function for call to `unrelated::printResult (commonAbstract *&, int (commonAbstract::)())'
bug.cc:45: candidates are: unrelated::printResult(commonAbstract *, int (commonAbstract::*)())
bug.cc:64: no matching function for call to `unrelated::printResult (commonAbstract *&, int (commonAbstract::)())'
bug.cc:45: candidates are: unrelated::printResult(commonAbstract *, int (commonAbstract::*)())

I'm compiling on a linux/libc6 system.  I enable haifa extensions when I
configured egcs.

I realize this could be a problem in my code - it's kind of a weird thing
to do :-)

Thanks,
	Dale

-- 
+--------------------  finger for pgp public key  ---------------------+
| Dale E. Martin | University of Cincinnati Savant Research Laboratory |
| dmartin@ececs.uc.edu    |     http://www.ececs.uc.edu/~dmartin       |
+----------------------------------------------------------------------+


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