I. CODE SAMPLE #include <stdio.h>
#define SHOWBUG class A; class F { public: F(A *x, void (A::*y)()) : m_x(x), m_y(y) {} void operator()(); private: A *m_x; void (A::*m_y)(); }; #ifdef SHOWBUG void F::operator()() { (m_x->*m_y)(); } #endif class A { public: void f() { printf("A::f()\n"); } }; #ifndef SHOWBUG void F::operator()() { (m_x->*m_y)(); } #endif int main() { A x; F f(&x, &A::f); f(); } II. EXPLANATION A is a class that has a method void f(). F is a class that wraps a void(A::*)() method. The program creates an A object, then it creates an F object that wraps the void f() method of the created A object, then it invokes operator() of the F object. The expected behaviour is that invoking the operator() of the F object should trigger the invocation of the f() method of the wrapped A object (which would print something on the console). The observed behaviour is that the A::f() method sometimes is invoked (as expected) and sometimes is not invoked (incorrect?). Whether the A::f() is correctly invoked by invoking the F::operator() method depends on the respective order in which class A and F::operator() are defined. By setting #define SHOWBUG, the A::f() is not invoked. By setting #undef SHOWBUG, the A::f() is invoked (as expected). The problem is that in both cases the code compiles fine with no warning whatsoever (even with -Wall). -- Summary: pointer-to-member stuff inconsistently compiled without warning Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: emmanuel dot garcia at infoterra dot fr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32416