In this testcase, we weren't instantiating Foobar<void> until fairly late, so the field and proxy variable didn't have a size, leading to madness.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.
commit 7082532a480501ab8f8f99bc62589a9045da303a
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Aug 30 10:38:52 2011 -0400

    	PR c++/50220
    	* semantics.c (add_capture): Call complete_type for copy.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1ad991f..dd7c013 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8651,6 +8651,9 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
       if (!real_lvalue_p (initializer))
 	error ("cannot capture %qE by reference", initializer);
     }
+  else
+    /* Capture by copy requires a complete type.  */
+    type = complete_type (type);
 
   /* Add __ to the beginning of the field name so that user code
      won't find the field with name lookup.  We can't just leave the name
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-50220.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-50220.C
new file mode 100644
index 0000000..240143c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-50220.C
@@ -0,0 +1,9 @@
+// PR c++/50220
+// { dg-options -std=c++0x }
+
+template<typename Foo> struct Foobar {};
+
+void foobar(const Foobar<void>& obj)
+{
+  [obj](){}();
+}

Reply via email to