From: Rodrigo Rivas <rodrigorivascosta@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: Jonathan Wakely <jwakely.gcc@gmail.com>,
gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [C++0x] Range-based for statements and ADL
Date: Thu, 31 Mar 2011 20:33:00 -0000 [thread overview]
Message-ID: <AANLkTik3T3Nd_28tL8+rOo0eZm2j4DATCP4u0OR9EGrK@mail.gmail.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2011-03-31 20:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AANLkTi=-PdaK2bni1d7ucHNNP2nSiDeJrnfET-ueaCvF@mail.gmail.com>
[not found] ` <AANLkTikxo7955t51av28NhGt4VhA89TyFE6WNPjd_eNE@mail.gmail.com>
[not found] ` <AANLkTinP2BzdG+fnO7n=5p+hvaU_VZ+-HyDLNn2Wy2J=@mail.gmail.com>
[not found] ` <4D8A2403.5050708@redhat.com>
[not found] ` <AANLkTimDRZ94xrA4OPziT7+X-bPK3xfAptTELFpVn-eR@mail.gmail.com>
[not found] ` <4D90A209.2020508@redhat.com>
[not found] ` <AANLkTintp7fzurBNiiOC+cmRoLt2CF9Q4SwSe04Y1AQa@mail.gmail.com>
[not found] ` <AANLkTimWyPccxiYbYG97H9Y6ddHVHFjv+RpgM14tmNyV@mail.gmail.com>
2011-03-29 1:07 ` Rodrigo Rivas
2011-03-29 9:00 ` Jonathan Wakely
2011-03-29 9:40 ` Rodrigo Rivas
2011-03-29 15:53 ` Gabriel Dos Reis
2011-03-29 16:55 ` Rodrigo Rivas
2011-03-29 18:57 ` Jonathan Wakely
2011-03-29 20:54 ` Rodrigo Rivas
2011-03-29 22:00 ` Jonathan Wakely
2011-03-29 22:55 ` Rodrigo Rivas
2011-03-31 17:33 ` Jason Merrill
2011-03-31 20:33 ` Rodrigo Rivas [this message]
2011-03-31 20:52 ` Jonathan Wakely
2011-04-06 23:22 ` Rodrigo Rivas
2011-04-08 15:45 ` Jason Merrill
2011-04-11 20:50 ` Rodrigo Rivas
2011-04-13 13:46 ` Jason Merrill
2011-04-14 14:42 ` Rodrigo Rivas
2011-04-16 3:00 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTik3T3Nd_28tL8+rOo0eZm2j4DATCP4u0OR9EGrK@mail.gmail.com \
--to=rodrigorivascosta@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=jwakely.gcc@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).