[cfe-dev] My first patch to clang

Charles Davis cdavis at mymail.mines.edu
Sat Dec 5 10:18:50 PST 2009


Ivan Sorokin wrote:
> Chris Lattner wrote:
>> "pointer to a record type for which the field would be valid".  We  
>> might as well test that the field makes sense as well.
>>
>> Thanks again for working on this, it's great to get this enhancement,
>>
>>   
> You need also to check if class has overloaded operator->.
No he doesn't. That's because, if you have a pointer to an object that
has an overloaded operator->(), using the -> operator on the pointer
doesn't cause the operator->() function to get called. I think it's best
shown with an example; continuing your example:

int main(void)
{
    c * c;

    c.d;    // illegal, suggest replacement
    c->d;   // dereferences c, accesses c::d
    (*c)->d;// dereferences c, calls c::operator->(), tries to
            // dereference a pointer to an object of type a and access
            // a::d (which fails)
    (*c)->b;// dereferences c, calls c::operator->(), dereferences a
            // pointer to an object of type a and accesses a::b

    return 0;
}

Chip
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list