This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] PR c++/61636


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 ());
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]