Patchwork C++ PATCH for c++/50220 (ICE with capture by copy of reference)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 30, 2011, 3:24 p.m.
Message ID <4E5D00B4.8060303@redhat.com>
Download mbox | patch
Permalink /patch/112353/
State New
Headers show

Comments

Jason Merrill - Aug. 30, 2011, 3:24 p.m.
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.

Patch

commit 7082532a480501ab8f8f99bc62589a9045da303a
Author: Jason Merrill <jason@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](){}();
+}