When presented with the attached code, gcc (taken from CVS on Dec. 6 2004) generates bad code for the function callpmf(). The code it generates never calls the member function, so the exit status of this program is garbage (I get 39). No diagnostic is issued when compiling.
If you replace the declaration of A with a trivial definition ("class A{};"), it generates the correct code. gcc-3.4.2 and earlier generated the correct code regardless of whether A was an incomplete type. ---- class A; class B { public: int memfn() { return 1; } }; int callpmf(A* a_ptr, int (A::*memfn_ptr)()) { return (a_ptr->*memfn_ptr)(); } int main() { B b; return callpmf((A*)&b, (int (A::*)())&B::memfn); } ---- This bug looks related to 15684, which seems to be debating whether this is a legal thing to do or not. If it is decided that this is illegal, a diagnostic would be helpful. -- Summary: pointer-to-member called on incomplete type generates bad code Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: efrias at syncad dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18933