From 892562cf28252bd284a4cd4d249f20c1755a6b5b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 19 Jun 2015 14:15:24 -0400 Subject: [PATCH] re PR c++/65843 (multiple use of const variable in lamba in template function causes compile error) PR c++/65843 * pt.c (tsubst_copy_and_build): Register a capture proxy in local_specializations. From-SVN: r224676 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 6 +++++- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index eb8d97ab1e8..4f2d4a6e27b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-06-19 Jason Merrill + + PR c++/65843 + * pt.c (tsubst_copy_and_build): Register a capture proxy in + local_specializations. + 2015-06-17 Jason Merrill PR c++/66001 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ccce90dba95..5dd5bfe55de 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15665,7 +15665,11 @@ tsubst_copy_and_build (tree t, r = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); } else if (outer_automatic_var_p (r)) - r = process_outer_var_ref (r, complain); + { + r = process_outer_var_ref (r, complain); + if (is_capture_proxy (r)) + register_local_specialization (r, t); + } if (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE) /* If the original type was a reference, we'll be wrapped in diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C new file mode 100644 index 00000000000..a35060b0a52 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C @@ -0,0 +1,14 @@ +// PR c++/65843 +// { dg-do compile { target c++11 } } + +template +void test(T b) +{ + const int a = b; + [&] () { return a, a; }(); +} + +int main() { + test(1); + return 0; +} -- 2.30.2