This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/53783 (wrong error on nested lambda)


A nested lambda in a template was complaining about use of an 'auto' function before its return type was deduced; this was because we were using tsubst_copy to instantiate LAMBDA_EXPR_EXTRA_SCOPE, i.e. treating it as an expression, which results in calling mark_used. Fixed by using tsubst instead.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 35f50b80cc3aad10bb7ce825ff37df57d4d46450
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jul 2 23:42:41 2012 -0400

    	PR c++/53783
    	* pt.c (tsubst_copy_and_build) [LAMBDA_EXPR]: Use tsubst
    	for LAMBDA_EXPR_EXTRA_SCOPE.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 563a1ad..d385ea7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14401,7 +14401,7 @@ tsubst_copy_and_build (tree t,
 	LAMBDA_EXPR_DISCRIMINATOR (r)
 	  = (LAMBDA_EXPR_DISCRIMINATOR (t));
 	LAMBDA_EXPR_EXTRA_SCOPE (r)
-	  = RECUR (LAMBDA_EXPR_EXTRA_SCOPE (t));
+	  = tsubst (LAMBDA_EXPR_EXTRA_SCOPE (t), args, complain, in_decl);
 	LAMBDA_EXPR_RETURN_TYPE (r)
 	  = tsubst (LAMBDA_EXPR_RETURN_TYPE (t), args, complain, in_decl);
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template7.C
new file mode 100644
index 0000000..5b098d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template7.C
@@ -0,0 +1,5 @@
+// PR c++/53783
+// { dg-do compile { target c++11 } }
+
+template <class T> void foo() { [] { [] {}; }; }
+int main() { foo<void>(); }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]