From 8afd9c45b6e84193b2fc12a2332191e28cdbdd70 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 20 Mar 2017 14:49:10 -0400 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 3 +++ .../g++.dg/cpp1y/lambda-generic-const3.C | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-const3.C 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>(); } -- 2.30.2