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]
Other format: [Raw text]

[Bug other/28945] New: extracting the function pointer from a bound pointer to member function doesn't work.


following testcase should work but it fails at least on ia32.

#include <cstdio>
struct base
{
        virtual ~base() { }
        virtual void foo() = 0;
        int val;
};
struct derived : public base
{
        void foo()
        {
                std::printf( "foo(): this -> %p, val = %d\n",
                        (void*)this, val );
        }
};
typedef void (* pf)();
void test( base* o, void (base::* pmf)() )
{
        pf f1 = (pf)( o->*pmf );
        f1();
}
int main()
{
        derived object;
        object.val = 7;
        test( &object, &base::foo );
        return 0;
};

$ g++ test.cpp -Wall -Wno-pmf-conversions -m32 -O0 && ./a.out
foo(): this -> 0xf7cd2412, val = -2046820353
$ g++ test.cpp -Wall -Wno-pmf-conversions -m32 -O1 && ./a.out
foo(): this -> 0xf7fbf6e0, val = -134501465
$ g++ test.cpp -Wall -Wno-pmf-conversions -m32 -O2 && ./a.out
foo(): this -> 0xffffceec, val = 7

$ g++ test.cpp -Wall -Wno-pmf-conversions -m64 -O0 && ./a.out
foo(): this -> 0x7fffff8afe20, val = 7
$ g++ test.cpp -Wall -Wno-pmf-conversions -m64 -O1 && ./a.out
foo(): this -> 0x7fffffe3af40, val = 7
$ g++ test.cpp -Wall -Wno-pmf-conversions -m64 -O2 && ./a.out
foo(): this -> 0x7fffffb443e0, val = 7


-- 
           Summary: extracting the function pointer from a bound pointer to
                    member function doesn't work.
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
GCC target triplet: ix86-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28945


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