8sa1-gcc/gcc/testsuite/g++.dg/cpp1z/lambda-this4.C
Jason Merrill 76f09260b7 c++: Fix DMI with lambda 'this' capture [PR94205]
We represent 'this' in a default member initializer with a PLACEHOLDER_EXPR.
Normally in constexpr evaluation when we encounter one it refers to
ctx->ctor, but when we're creating a temporary of class type, that replaces
ctx->ctor, so a PLACEHOLDER_EXPR that refers to the type of the member being
initialized needs to be replaced before that happens.

gcc/cp/ChangeLog
2020-03-31  Jason Merrill  <jason@redhat.com>

	PR c++/94205
	* constexpr.c (cxx_eval_constant_expression) [TARGET_EXPR]: Call
	replace_placeholders.
	* typeck2.c (store_init_value): Fix arguments to
	fold_non_dependent_expr.
2020-04-01 01:17:23 -04:00

14 lines
187 B
C

// PR c++/94205
// { dg-do compile { target c++17 } }
struct S
{
int i;
int a = [this] { this->i = 5; return 6; } ();
};
constexpr S s = {};
static_assert (s.i == 5 && s.a == 6);