[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    Re: [PATCH] Optimize pointers to member function
From:       John McCall <rjmccall () apple ! com>
Date:       2013-02-14 21:49:23
Message-ID: EA367A62-CC7C-4C4C-9CB3-2307A03D626F () apple ! com
[Download RAW message or body]

On Feb 14, 2013, at 1:42 PM, Olivier Goffart <ogoffart@kde.org> wrote:
> On Thursday 14 February 2013 12:20:31 Richard Smith wrote:
>> On Thu, Feb 14, 2013 at 11:58 AM, Olivier Goffart <ogoffart@kde.org> wrote:
>>> On Thursday 14 February 2013 11:05:28 John McCall wrote:
>>>> On Feb 14, 2013, at 3:57 AM, Olivier Goffart <ogoffart@kde.org> wrote:
>>>> 
>>>> A pointer-to-member may point to a member of a derived class.
>>> 
>>> How?
>>> 
>>> struct A { void m(); };
>>> struct B : A { void n(); };
>>> int main() { void (A::*t)() = &B::n; }
>>> 
>>> error: cannot initialize a variable of type 'void (A::*)()' with an rvalue
>>> of type 'void (B::*)()': different classes ('A' vs 'B')
>>> 
>>> C++11[4.11.2]
>>> 
>>>   A prvalue of type “pointer to member of B of type cv T”, where B is a
>>>   class type, can be converted to a prvalue of type “pointer to member of
>>>   D of type  cv T”, where D is a derived class (Clause 10) of B. [...]
>>> 
>>> You can convert from a base to a derived, but not the other way around.
>> 
>> [expr.static.cast]p12.
> 
> There I read: 
> 
>   [...] If class B contains the original member, or is a base or derived
>   class of the class containing the original member, the resulting pointer to
>   member points to the original member. Otherwise, the result of the cast is
>   undefined.
> 
>> int main() { void (A::*t)() = (void(A::*)())&B::n; }
> 
> So that cast is undefined.

The original member is B::n, and A is a base class of the class containing
the original member.

John.
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic