This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++0x] Range-based for statements and ADL
- From: Rodrigo Rivas <rodrigorivascosta at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Jonathan Wakely <jwakely dot gcc at gmail dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 31 Mar 2011 22:22:35 +0200
- Subject: Re: [C++0x] Range-based for statements and ADL
- References: <AANLkTi=-PdaK2bni1d7ucHNNP2nSiDeJrnfET-ueaCvF@mail.gmail.com> <AANLkTikxo7955t51av28NhGt4VhA89TyFE6WNPjd_eNE@mail.gmail.com> <AANLkTinP2BzdG+fnO7n=5p+hvaU_VZ+-HyDLNn2Wy2J=@mail.gmail.com> <4D8A2403.5050708@redhat.com> <AANLkTimDRZ94xrA4OPziT7+X-bPK3xfAptTELFpVn-eR@mail.gmail.com> <4D90A209.2020508@redhat.com> <AANLkTintp7fzurBNiiOC+cmRoLt2CF9Q4SwSe04Y1AQa@mail.gmail.com> <AANLkTimWyPccxiYbYG97H9Y6ddHVHFjv+RpgM14tmNyV@mail.gmail.com> <4D94B85F.1030603@redhat.com>
On Thu, Mar 31, 2011 at 7:22 PM, Jason Merrill <jason@redhat.com> 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