On 3/18/22 14:47, Jakub Jelinek wrote:
On Fri, Mar 18, 2022 at 02:27:30PM -0400, Jason Merrill wrote:
That is also correct C++ expression, but user probably has no idea what is
present at offset 32 into the variable.
Of course if there is a type match and not any kind of type punning,
it will try to print much shorter and more readable expressions.
One important point about the OP's testcase is that we're dealing with
offset 0, which corresponds to both the PMF as a whole and its first
element. Since we're looking for a RECORD_TYPE, choosing to interpret the
desired object as the (RECORD_TYPE) PMF as a whole seems like the better
choice; being more flexible probably does make sense at non-0 offsets.
Even if we punt for 0 offsets in RECORD_TYPEs, we'd still run into
the ICE if we tried to access something overlapping the __delta member.
Good point. Your patch is OK, then.
For 0 offsets and type puning, the question is what will help user more,
it is true we don't need to print those + offsetof(...) parts because it
is the start of it, on the other side the user might not know what is the
first member of the struct and printing that might sometimes help.
Or it might not, as in this case. Going with the enclosing class if
none of the types match seems like a better default to me, but I guess
let's not worry about it now.
Jason