Commit 01826160 by Jason Merrill Committed by Jason Merrill

PR c++/88761 - ICE with reference capture of constant.

Here, we capture nf, then the use of the proxy decays to a constant during
semantic processing of +nf.  Since we saw some decay from proxy to constant,
we walk through the lambda body to see which proxies are still used, but we
weren't walking into subtrees of DECL_EXPR at all, so we missed the use of
&nf in the initializer of y, and removed the capture.  But then at
instantiation time we try to use nf, don't have a proxy anymore, and ICE.

	* lambda.c (mark_const_cap_r): Do walk subtrees of DECL_EXPR for
	non-proxy decls.

From-SVN: r268471
parent fde81c6f
2019-02-01 Jason Merrill <jason@redhat.com>
PR c++/88761 - ICE with reference capture of constant.
* lambda.c (mark_const_cap_r): Do walk subtrees of DECL_EXPR for
non-proxy decls.
2019-02-01 Marek Polacek <polacek@redhat.com> 2019-02-01 Marek Polacek <polacek@redhat.com>
PR c++/88325 - ICE with invalid out-of-line template member definition. PR c++/88325 - ICE with invalid out-of-line template member definition.
......
...@@ -1488,8 +1488,10 @@ mark_const_cap_r (tree *t, int *walk_subtrees, void *data) ...@@ -1488,8 +1488,10 @@ mark_const_cap_r (tree *t, int *walk_subtrees, void *data)
{ {
tree decl = DECL_EXPR_DECL (*t); tree decl = DECL_EXPR_DECL (*t);
if (is_constant_capture_proxy (decl)) if (is_constant_capture_proxy (decl))
var = DECL_CAPTURED_VARIABLE (decl); {
*walk_subtrees = 0; var = DECL_CAPTURED_VARIABLE (decl);
*walk_subtrees = 0;
}
} }
else if (is_constant_capture_proxy (*t)) else if (is_constant_capture_proxy (*t))
var = DECL_CAPTURED_VARIABLE (*t); var = DECL_CAPTURED_VARIABLE (*t);
......
// PR c++/88761
// { dg-do compile { target c++14 } }
template <class T>
void f(T t) { t(1); }
int main()
{
const unsigned long nf = 10'000'000;
auto loop = [&](auto)
{
auto x = +nf;
auto y = &nf;
};
f(loop);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment