re PR c++/65843 (multiple use of const variable in lamba in template function causes...
authorJason Merrill <jason@redhat.com>
Fri, 19 Jun 2015 18:15:24 +0000 (14:15 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 19 Jun 2015 18:15:24 +0000 (14:15 -0400)
PR c++/65843
* pt.c (tsubst_copy_and_build): Register a capture proxy in
local_specializations.

From-SVN: r224676

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-rep1.C [new file with mode: 0644]

index eb8d97ab1e8a400b485a9990fed21bcd66ec0b60..4f2d4a6e27bbea36a7f2475a40a3ee0f696b737c 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/65843
+       * pt.c (tsubst_copy_and_build): Register a capture proxy in
+       local_specializations.
+
 2015-06-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/66001
index ccce90dba954fa6993219115a607d7c211de51d6..5dd5bfe55ded08de40e78f1dcc55be4b3ea6dd1f 100644 (file)
@@ -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 (file)
index 0000000..a35060b
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/65843
+// { dg-do compile { target c++11 } }
+
+template<class T>
+void test(T b)
+{
+    const int a = b;
+    [&] () { return a, a; }();
+}
+
+int main() {
+    test(1);
+ return 0;
+}