8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv13.C
Jason Merrill 538a530848 PR c++/86943 - wrong code converting lambda to function pointer.
In this PR, instantiating the static thunk returned from the generic lambda
conversion function template was using normal overload resolution, which
meant calling an extra constructor when forwarding its argument.  Fixed by
special-casing thunk calls significantly more.

	* lambda.c (maybe_add_lambda_conv_op): Use a template-id in the
	call.  Only forward parms for decltype.
	* pt.c (tsubst_copy_and_build) [CALL_EXPR]: Handle CALL_FROM_THUNK_P
	specially.
	* typeck.c (check_return_expr): Don't mess with a thunk call.

From-SVN: r268377
2019-01-29 21:43:04 -05:00

34 lines
594 B
C

// PR c++/86943
// { dg-do run { target c++14 } }
int c[3];
struct S
{
S () : s (1234) { c[0]++; }
S (const S &) { __builtin_abort (); }
S (S &&x) noexcept { if (x.s != 1234) __builtin_abort (); s = 1234; x.s = 2345; c[1]++; }
~S () { if (s != 1234 && s != 2345) __builtin_abort (); c[2]++; }
int s;
};
using F = S (*) (S);
F
foo ()
{
return [] (auto val)->S { if (val.s != 1234) __builtin_abort (); return {}; };
}
int
main ()
{
{
volatile F f = foo ();
S s = f ({});
if (s.s != 1234) __builtin_abort ();
}
if (c[0] + c[1] != c[2])
__builtin_abort ();
}