From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21243 invoked by alias); 31 Mar 2011 20:22:46 -0000 Received: (qmail 21222 invoked by uid 22791); 31 Mar 2011 20:22:42 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 Mar 2011 20:22:37 +0000 Received: by wwf26 with SMTP id 26so3227360wwf.8 for ; Thu, 31 Mar 2011 13:22:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.144.134 with SMTP id n6mr441840wej.27.1301602956107; Thu, 31 Mar 2011 13:22:36 -0700 (PDT) Received: by 10.216.78.132 with HTTP; Thu, 31 Mar 2011 13:22:35 -0700 (PDT) In-Reply-To: <4D94B85F.1030603@redhat.com> References: <4D8A2403.5050708@redhat.com> <4D90A209.2020508@redhat.com> <4D94B85F.1030603@redhat.com> Date: Thu, 31 Mar 2011 20:33:00 -0000 Message-ID: Subject: Re: [C++0x] Range-based for statements and ADL From: Rodrigo Rivas To: Jason Merrill Cc: Jonathan Wakely , gcc-patches List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg02278.txt.bz2 On Thu, Mar 31, 2011 at 7:22 PM, Jason Merrill 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... >> + =C2=A0id_begin =3D get_identifier ("begin"); >> + =C2=A0*begin =3D build_qualified_name (/*type=3D*/NULL_TREE, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TREE_TYPE (range), >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id_begin, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/*template_p=3D*/fal= se); >> + =C2=A0*begin =3D finish_class_member_access_expr(range, *begin, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0false, 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 w= ant > to fall back to ADL) and an access violation (in which case we want to gi= ve > 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