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.
14 lines
187 B
C
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);
|