On Thu, Feb 14, 2013 at 11:58 AM, Olivier Goffart <span dir="ltr"><<a href="mailto:ogoffart@kde.org" target="_blank">ogoffart@kde.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Thursday 14 February 2013 11:05:28 John McCall wrote:<br>
> On Feb 14, 2013, at 3:57 AM, Olivier Goffart <<a href="mailto:ogoffart@kde.org">ogoffart@kde.org</a>> wrote:<br>
> > This patch optimize comparison and calling of pointers to member function.<br>
> ><br>
> > If we know that a given class do not have multiple inheritance, we can<br>
> > simplify the comparison and the calls as the pointer to this will never be<br>
> > shifted.<br>
> > On the Microsoft ABI (which is not implemented in clang), the size of a<br>
> > pointer to a member function is even reduced in that case.[1]<br>
><br>
> A pointer-to-member may point to a member of a derived class.<br>
<br>
</div>How?<br>
<br>
struct A { void m(); };<br>
struct B : A { void n(); };<br>
int main() { void (A::*t)() = &B::n; }<br>
<br>
error: cannot initialize a variable of type 'void (A::*)()' with an rvalue of<br>
type 'void (B::*)()': different classes ('A' vs 'B')<br>
<br>
<br>
C++11[4.11.2]<br>
   A prvalue of type “pointer to member of B of type cv T”, where B is a class<br>
   type, can be converted to a prvalue of type “pointer to member of D of type<br>
   cv T”, where D is a derived class (Clause 10) of B. [...]<br>
<br>
You can convert from a base to a derived, but not the other way around.<br></blockquote><div><br></div><div>[expr.static.cast]p12.</div><div><br></div><div>int main() { void (A::*t)() = (void(A::*)())&B::n; }</div><div>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Notice that since Microsoft changes the size of the pointer depending on that<br>
fact, it means it cannot be possible to point to a member of a derived class.</blockquote><div><br></div><div>No, it means Microsoft's implementation is non-conforming. See MS compiler warning C4407.</div></div>