From: Jason Merrill Date: Mon, 20 Mar 2017 18:49:10 +0000 (-0400) Subject: PR c++/79640 - infinite recursion with generic lambda. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8afd9c45b6e84193b2fc12a2332191e28cdbdd70;p=gcc.git PR c++/79640 - infinite recursion with generic lambda. * pt.c (tsubst_copy) [VAR_DECL]: Register the dummy instantiation before substituting its initializer. From-SVN: r246289 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a356fc77924..2797f8c7157 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-03-20 Jason Merrill + + PR c++/79640 - infinite recursion with generic lambda. + * pt.c (tsubst_copy) [VAR_DECL]: Register the dummy instantiation + before substituting its initializer. + 2017-03-20 Marek Polacek Paolo Carlini diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b8ce9fedf42..f1807106815 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14581,6 +14581,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) local static or constant. Building a new VAR_DECL should be OK in all those cases. */ r = tsubst_decl (t, args, complain); + if (local_specializations) + /* Avoid infinite recursion (79640). */ + register_local_specialization (r, t); if (decl_maybe_constant_var_p (r)) { /* We can't call cp_finish_decl, so handle the diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-const3.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-const3.C new file mode 100644 index 00000000000..9c9dbac70ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-const3.C @@ -0,0 +1,15 @@ +// PR c++/79640 +// { dg-do compile { target c++14 } } + +template void foo(F f) +{ + f(1); +} + +template void bar() +{ + const int i = i; + foo([] (auto) { sizeof(i); }); +} + +void baz() { bar<1>(); }