[patch] Fix second part of PR c++/27601: ICE using offsetof with member functions
Mark Mitchell
mark@codesourcery.com
Tue Jun 6 21:29:00 GMT 2006
Volker Reichelt wrote:
> On 6 Jun, Mark Mitchell wrote:
>> If you're correct that we have to recurse, then I agree -- but why do we
>> have to recurse?
>
> Thinko on my part. In cases like
>
> struct A { int i; };
> struct B { A a; };
> struct C { B b; };
>
> int j = __builtin_offsetof(C, C::b.a.i);
>
> we not only have to check whether ".i" is valid, but we also have to
> check whether the first part makes sense.
Wow, I wouldn't expect that to be valid. I'd expect that the second
argument had to be a member of the type given by the first. However, if
C allows b.a here, then so should C++, I suppose.
> But for member functions the situation is different (and that's what
> I failed to see): As functions cannot have members, we know that the
> C::b.a part does not contain a member function. Only the last part can
> be a function. And therefore we don't have to recurse to check for
> member functions.
Right.
> I'm not sure about TYPE_OBJ_P, though, since this would also flag
> references as errors. We now only emit a warning in this case - even
> for "A& A;" or "B& b;" in the case above. Making this consistent
> would require recursion. Therefore I'd rather only check for
> FUNCTION_TYPE and METHOD_TYPE.
That sounds fine to me.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
More information about the Gcc-patches
mailing list