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]

c++/2218: Problem with pointers on class-member functions



>Number:         2218
>Category:       c++
>Synopsis:       Problem with pointers on class-member functions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 07 16:06:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Stephane Brunet
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
i686-pc-linux, Mandrake 7.1, 2.4.2 kernel
>Description:
When attempting to compile the program below (see How-To-Repeat), GCC produce the following output :

---------------- Start ----------------
Reading specs from /usr/lib/gcc-lib/i686-pc-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/lib/gcc-lib/i686-pc-linux/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ test.cc test.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/i686-pc-linux/2.95.2/../../../../include/g++-3
 /usr/include
 /usr/lib/gcc-lib/i686-pc-linux/2.95.2/../../../../i686-pc-linux/include
 /usr/lib/gcc-lib/i686-pc-linux/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/lib/gcc-lib/i686-pc-linux/2.95.2/cc1plus test.ii -quiet -dumpbase test.cc -version -o test.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux) compiled by GNU C version 2.95.2 19991024 (release).
test.cc: In method `void Test::helloFunc()':
test.cc:6: no matching function for call to `Test::executeFunction ({unknown type})'
test.cc:8: candidates are: void Test::executeFunction(void (*)())
-------------- End --------------

Note that function pointer "helloFunc" should have been of type "void (*)()" and is not recognized as this by the compiler.

Moreover, the gcc under development also rejects this code.

>How-To-Repeat:
Try this program...

#include <iostream>

class Test {
public:
  void helloFunc() {
    executeFunction(hello);
  };
  void executeFunction( void (*fnt) () ) {
    (*fnt)();
  };
private:
  void hello();
};

void helloagain() {
  std::cout << "Hello again!!" << std::endl;
}

void Test::hello(){
  std::cout << "Hello!!" << std::endl;
}

int main() {
  Test test;
  test.helloFunc();
  test.executeFunction( helloagain );
  return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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