<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57593>57593</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang does not call derived virtual class function when invoked from pointer to class member
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mwittgen
</td>
</tr>
</table>
<pre>
Code to reproduce behavior below.
This behavior differs between `clang` and clang based compilers like `ipcx` and `gcc`/`MSVC`
The below code works for clang versions `<4.0.0` and older Intel compiler versions
Broken code: https://godbolt.org/z/r9rnv57Ye
clang requires to make `func()` pure virtual for this to work
Working code: https://godbolt.org/z/957hKM99z
```
#include <iostream>
#include <vector>
class Base {
public:
Base() = default;
virtual ~Base() = default;
virtual void func() {
std::cout << "Base\n";
}
};
class Derived : public Base {
public:
virtual void func() {
std::cout << "Derived\n";
}
};
class Test {
public:
Test() = default;
~Test() = default;
Base reg1;
Derived reg2;
Base Test::* r1 = &Test::reg1;
Base Test::* r2 = reinterpret_cast<Base Test::*>(&Test::reg2);
void write() {
(this->*r1).func();
(this->*r2).func(); /* should print Derived */
Base *b=reinterpret_cast<Base *>(®2);
b->func();
}
};
int main() {
Test test;
test.write();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVV2TkzAU_TXhJSNDw1LKAw_90BnH8UlHxycnkNsSNyWYBKr-em-SZdvurrpqh0I-LifnnOReGi2-11stgDpNDQxGi7EF2kDHJ6kNNpQ-pZRkO5Kt33fSnqeE3O_B-AF3AugpWWat4v0Bn5T3goYObbgFbOvjIJWPVvIWfKgc2m9zJD4PbYt3wl7h_e27D1vfuVsTIgnEQJYnbW4t3ePyEX5CTKl76zFIvr1JszSbYbUSYOjr3oG6J3D_QkTfGH2L1D00yde0c26w2PA82KuDFo1WLtXmgL0f-DeV6aei_ATx7XiPRAx8HaUB63088qhxP_YtYSvCKk9p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