On Thu, Mar 31, 2011 at 7:22 PM, Jason Merrill <[email protected]> wrote:
> On 03/28/2011 08:28 PM, Rodrigo Rivas wrote:
>>
>> A few comments:
>> 1. I'm not sure about what should happen if the begin/end found in class
>> scope are not ordinary functions.
>
> Whatever range.begin() would mean if written explicitly.
>
>> My guess is that if it is a function
>> (static or non-static) it is called normally, and if it is a member
>> variable it is searched for an operator()(). If it is a type it should
>> fail.
>
> Yes, because we can't use . syntax to name type members.
Yeah, actually what I meant is whether:
struct S { typedef int begin, end; };
//...
for (auto x : S()) ;
should fall back to ADL or else fail at once. My guess is that is
should fail, but curiously enough my patch does ADL...
>> + id_begin = get_identifier ("begin");
>> + *begin = build_qualified_name (/*type=*/NULL_TREE,
>> + TREE_TYPE (range),
>> + id_begin,
>> + /*template_p=*/false);
>> + *begin = finish_class_member_access_expr(range, *begin,
>> + false, tf_none);
>
> Don't call build_qualified_name here; the standard doesn't say
> range.T::begin(), just range.begin().
That's curious, because I tested with virtual functions with a class
hierarchy, and it worked as expected. My understanding is that the
range.T::begin() syntax would require a call to
adjust_result_of_qualified_name_lookup.
But again, I've just tried removing the call to build_qualified_name
and it works just the same. It looks to me that
finish_class_member_access_expr is a super-smart functions and "just
works" with many kinds of input.
> Also, we can't just call finish_class_member_access_expr here because it
> returns error_mark_node for any error condition, so we can't tell the
> difference between a lookup that didn't find anything (in which case we want
> to fall back to ADL) and an access violation (in which case we want to give
> an error).
I'll dare say that you are wrong with this one, if only because I've
just debugged it. If the member begin is private, for instance,
finish_class_member_access_expr returns ok, and then the error is
emitted from build_new_method_call.
> We need to do the lookup directly first, and then do
> finish_class_member_access_expr after we've decided to use the members.
But maybe you are right here anyway, because I think that there may be
are errors from finish_class_member_access_expr that we want to
diagnose right away and errors that we want to silence, and the
tsubst_flags_t does not do this.
I'm preparing another patch with your suggestions and a few testcases.
Regards.
--
Rodrigo