[LLVMbugs] [Bug 22121] New: Clang will not accept a conversion from a bound pmf(Pointer to member function) to a regular method pointer. Gcc accepts this.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jan 7 19:39:52 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22121

            Bug ID: 22121
           Summary: Clang will not accept a conversion from a bound
                    pmf(Pointer to member function) to a regular method
                    pointer. Gcc accepts this.
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: turboloops at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

This code below work and combines well on Gcc. With this code I can extract any
pointer to a function so that I can have Delphi style events. But Clang reports 

source_file.cpp:37:3: error: cannot cast from type 'int (A::*)(int)' to pointer
type 'MyProc' (aka 'int (*)(void *)')
  __methodv(int,Xyz,int y) { return 5 + y;}
  ^~~~~~~~~~~~~~~~~~~~~~~~
source_file.cpp:13:49: note: expanded from macro '__methodv'
 virtual void* __get_ptr_##name() { MyProc aa = (MyProc)&this_t::name; void**
bb = (void**)&aa; return *bb; }\
                                                ^~~~~~~~~~~~~~~~~~~~~
source_file.cpp:44:3: error: cannot cast from type 'int (B::*)(int)' to pointer
type 'MyProc' (aka 'int (*)(void *)')
  __methodv(int,Xyz,int x) {
  ^~~~~~~~~~~~~~~~~~~~~~~~
source_file.cpp:13:49: note: expanded from macro '__methodv'
 virtual void* __get_ptr_##name() { MyProc aa = (MyProc)&this_t::name; void**
bb = (void**)&aa; return *bb; }\
                                                ^~~~~~~~~~~~~~~~~~~~~
source_file.cpp:52:10: warning: unused variable 'i' [-Wunused-variable]
    auto i = 5;
         ^
source_file.cpp:72:11: warning: unused variable 'xx' [-Wunused-variable]
    void* xx = a->__get_ptr_Xyz();
          ^
source_file.cpp:76:10: warning: unused variable 'ff' [-Wunused-variable]
    auto ff = std::bind(&decltype(b)::Abc,b);
         ^
source_file.cpp:61:10: warning: unused variable 'method' [-Wunused-variable]
    auto method = &decltype(b)::Xyz;

// END OF ERRORS


So all it has to do is look at the pmf and just give me the pointer. Once I
have the pointer everything is well. A way to silence the warnings is also
helpful.




// START OF CODE
#include <iostream>
#include <algorithm>
#include <functional>
//#include <windows.h>

using namespace std;

typedef int(*MyProc)(void* b);

#define __cdecl

#define __methodv(type,name,...)\
 virtual void* __get_ptr_##name() { MyProc aa = (MyProc)&this_t::name; void**
bb = (void**)&aa; return *bb; }\
 virtual __cdecl type name( __VA_ARGS__ ) \

template<class resultT, class A>
struct TFunction1 {
  typedef __cdecl resultT (*TProc)(void*,A);
  TProc proc;
  void* instance;
  TFunction1(void* _instance, void* _proc) {
    proc = (TProc)_proc;
    instance = _instance;
  }
  inline __attribute__((always_inline)) resultT operator()(A a) {
    return proc(instance,a);
  }
};

using TNotifyInts = TFunction1<int,int>;


class A {
public:
  using this_t = A;
  virtual int Abc() { return 0; }
  __methodv(int,Xyz,int y) { return 5 + y;}
};

class B: public A {
public:
  using this_t = B;
  int Abc() override { return 1; }
  __methodv(int,Xyz,int x) {
    //printf("dfg\n");
    return 5 + x;
  }
};

int main()
{
    auto i = 5;
    cout << "Hello world!" << endl;

    A* a;
    B b;
    a = &b;



    auto method = &decltype(b)::Xyz;


    typedef int(*MyProc)(void* b);


    #define __PMFX(obj,method)\
      obj , obj->__get_ptr_##method()


    //MyProc xx = (MyProc)&std::remove_reference<decltype((*a))>::type::Abc;
    void* xx = a->__get_ptr_Xyz();
    auto MyFunc1 = TNotifyInts(__PMFX(a,Xyz));

    //DWORD dw = GetTickCount();
    auto ff = std::bind(&decltype(b)::Abc,b);
    int x = 0;
    while (x < 10000000) {
      //a->Abc();

      //(((B*)a)->*method)(1);
      //xx(a);
      MyFunc1(5);
      //ff();
      x++;
    }
   // std::cout << GetTickCount() - dw << "\n";


//    auto f = std::bind(b.Abc)

    return 0;
}


Is there any way to enable this in clang or is it a bug?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150108/19ca9452/attachment.html>


More information about the llvm-bugs mailing list