8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-constexpr1.C
Jason Merrill 9f143008c7 c++: Fix reuse of class constants [PR94453]
The testcase hit an ICE trying to expand a TARGET_EXPR temporary cached from
the other lambda-expression.  This patch fixes this in two ways:

1) Avoid reusing a TARGET_EXPR from another function.
2) Avoid ending up with a TARGET_EXPR at all; the use of 'p' had become
<TARGET_EXPR<NON_LVALUE_EXPR<TARGET_EXPR ...>>>, which doesn't make any
sense.

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

	PR c++/94453
	* constexpr.c (maybe_constant_value): Use break_out_target_exprs.
	* expr.c (mark_use) [VIEW_CONVERT_EXPR]: Don't wrap a TARGET_EXPR in
	NON_LVALUE_EXPR.
2020-04-04 11:06:31 -04:00

29 lines
508 B
C

// PR c++/94453
// { dg-do compile { target c++11 } }
void *ay();
template <typename f> f ay() { return *static_cast<f *>(ay()); }
template <typename h>
void bf() {
ay<h>()();
}
struct az {
template <typename h>
az(h);
using bk = void (*)();
bk bl;
};
template <typename h>
az::az(h) { bl = bf<h>; }
struct A {};
void da(az);
void di(A, int);
void dk(A, az, az);
void b() {
int data = 0;
auto n = [] {};
constexpr auto p = A{};
auto q = [=] { di(p, data); };
da([=] { dk(p, n, q); });
}