public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Adam Butcher <adam@jessamine.co.uk>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 1/2] 	PR c++/61636
Date: Sat, 18 Apr 2015 17:53:00 -0000	[thread overview]
Message-ID: <2c51b8076a5ca562f87d7ba0ac8d5a70@imap.force9.net> (raw)
In-Reply-To: <a43dcccf0160b43bb7f515299d9b727b@imap.force9.net>

On 2015-04-17 22:06, Adam Butcher wrote:
> On 2015-04-17 20:58, Jason Merrill wrote:
>> On 04/09/2015 11:31 PM, Adam Butcher wrote:
>>> +		/* For generic lambdas, resolve default captured 'this' now.  */
>>>
>> This isn't quite right.  We don't want to capture 'this' any time we
>> see a member function call, as overload resolution might choose a
>> static member function that doesn't need 'this'.  The special 
>> handling
>> we want is for the case where the call depends on a generic lambda
>> parameter, in which case we capture 'this' because the call "names
>> [this] in a potentially-evaluated expression (3.2) where the 
>> enclosing
>> full-expression depends on a generic lambda parameter declared 
>> within
>> the reaching scope of the lambda-expression."
>>
> Good point.  I'll look into it.  So for a nullary member call we will
> always capture 'this', but for N-ary, we only capture if we find one
> of the lambda's parameters (or a parameter from an enclosing generic
> lambda?) in the call's arguments right?
>

Test like this?

/* { dg-do run { target c++14 } }  */
/* { dg-final { scan-assembler-not "..." } }  */

struct X
{
   int f (int, double) { return 255; }
   static int f (int, int) { return 65535; }

   auto m1 ()
   {
     return [=] (auto a) {
       return f (7, a);
     };
   }

   auto m2 ()
   {
     return [=] (auto a) {
       return f (9, 10) + a;
     };
   }
};

#include <cassert>

int main()
{
   X x;
   assert (x.m1 () (42.0) == 255);
   assert (x.m1 () (42) == 65535);
   assert (x.m2 () (42.0) == (65535 + 42));
   assert (x.m2 () (42) == (65535 + 42));
   assert (sizeof x.m2 () < sizeof x.m1 ());
}


  reply	other threads:[~2015-04-18 17:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 22:37 [PATCH] [PR c++/61636 and c++/64382] Fix default capture in generic lambdas Adam Butcher
2015-04-13 22:37 ` [PATCH 1/2] PR c++/61636 * cp/parser.c (cp_parser_postfix_expression): Resolve default captured 'this' early for " Adam Butcher
2015-04-17 19:58   ` [PATCH 1/2] PR c++/61636 Jason Merrill
2015-04-17 21:06     ` Adam Butcher
2015-04-18 17:53       ` Adam Butcher [this message]
2015-04-19 19:03         ` Adam Butcher
2015-04-20  3:28           ` Jason Merrill
2015-04-20 10:25         ` [PATCH 1/2] ?PR c++/61636 Marek Polacek
2015-04-20 19:46           ` Adam Butcher
2015-04-13 22:37 ` [PATCH 2/2] PR c++/64382 * cp/parser.c (parsing_default_capturing_generic_lambda_in_template): New function. * cp/cp-tree.h: Declare it. * cp/semantics.c (finish_id_expression): Resolve names within a default capturing generic lambda defined within a template prior to instantiation to allow for captures to be added to the closure type Adam Butcher
2015-04-14  7:16   ` Marek Polacek
2015-04-14  7:26     ` Jakub Jelinek
2015-04-14 18:00       ` Adam Butcher
2015-04-14 18:38   ` [PATCH 2/2] PR c++/64382 * cp/parser.c (parsing_default_capturing_generic_lambda_in_template) Adam Butcher

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=2c51b8076a5ca562f87d7ba0ac8d5a70@imap.force9.net \
    --to=adam@jessamine.co.uk \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.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).