<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Clang will not accept a conversion from a bound pmf(Pointer to member function) to a regular method pointer. Gcc accepts this."
href="http://llvm.org/bugs/show_bug.cgi?id=22121">22121</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang will not accept a conversion from a bound pmf(Pointer to member function) to a regular method pointer. Gcc accepts this.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows XP
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>turboloops@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>