diff mbox

C++ PATCH for c++/49598 (ICE with value capture of reference)

Message ID 4E1324AE.9090902@redhat.com
State New
Headers show

Commit Message

Jason Merrill July 5, 2011, 2:50 p.m. UTC
Need to convert_from_reference a decl that we're using as a normal 
expression, as in this case as an initializer.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit b5c0742c0bfe7fe58dba443d47f880c26eea1b82
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jul 5 01:13:04 2011 -0400

    	PR c++/49598
    	* semantics.c (finish_id_expression): convert_from_reference.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 619c058..fa22bc9 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2942,7 +2942,7 @@  finish_id_expression (tree id_expression,
 	  tree containing_function = current_function_decl;
 	  tree lambda_stack = NULL_TREE;
 	  tree lambda_expr = NULL_TREE;
-	  tree initializer = decl;
+	  tree initializer = convert_from_reference (decl);
 
 	  /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
 	     support for an approach in which a reference to a local
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C
new file mode 100644
index 0000000..15f1d90
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C
@@ -0,0 +1,13 @@ 
+// PR c++/49598
+// { dg-options -std=c++0x }
+// { dg-do run }
+
+int
+main()
+{
+  int i = 10;
+  int& ir = i;
+
+  if ([=]{ return ir; }() != 10)
+    return 1;
+}