Patchwork C++ PATCH for c++/57526 (ICE with capture of auto* variable)

login
register
mail settings
Submitter Jason Merrill
Date July 9, 2013, 5:46 p.m.
Message ID <51DC4C80.7040409@redhat.com>
Download mbox | patch
Permalink /patch/257850/
State New
Headers show

Comments

Jason Merrill - July 9, 2013, 5:46 p.m.
An earlier patch of mine changed lambda_capture_field_type to avoid 
building a DECLTYPE_TYPE in cases where it isn't really necessary, but 
it is necessary in the case of capture of an auto variable.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.

Patch

commit 80bb7027cca5a7c0db92fb0338ae55cb44e9b3d6
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jul 9 02:59:52 2013 -0400

    	PR c++/57526
    	* semantics.c (lambda_capture_field_type): Build a DECLTYPE_TYPE
    	if the variable type uses 'auto'.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 57700f7..3699ea5 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9078,7 +9078,8 @@  lambda_capture_field_type (tree expr)
 {
   tree type;
   if (type_dependent_expression_p (expr)
-      && !(TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE))
+      && !(TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE
+	   && !type_uses_auto (TREE_TYPE (expr))))
     {
       type = cxx_make_type (DECLTYPE_TYPE);
       DECLTYPE_TYPE_EXPR (type) = expr;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C
new file mode 100644
index 0000000..013ed52
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-auto3.C
@@ -0,0 +1,24 @@ 
+// PR c++/57526
+// { dg-require-effective-target c++11 }
+
+template<class T>
+struct A
+{
+  void bar( ) { }
+
+  void foo( )
+  {
+    auto* this_ptr = this;
+    auto lc = [&]( )
+      {
+	this_ptr->bar();
+      };
+    lc();
+  }
+};
+
+int main()
+{
+  A<int> a;
+  a.foo();
+}