Patchwork C++ PATCH for c++/50224 (bogus unused parameter warning with lambda)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 30, 2011, 4:28 a.m.
Message ID <4E5C66D2.9000109@redhat.com>
Download mbox | patch
Permalink /patch/112178/
State New
Headers show

Comments

Jason Merrill - Aug. 30, 2011, 4:28 a.m.
The lambda capture path in finish_id_expression wasn't calling mark_used 
like the other paths.

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

Patch

commit 0aceb42a8ba7bde23447d6ae74c8615721a40952
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Aug 29 11:23:56 2011 -0400

    	PR c++/50224
    	* semantics.c (finish_id_expression): Mark captured variables used.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5deb2eb..07f53b5 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2949,6 +2949,9 @@  finish_id_expression (tree id_expression,
 	  tree lambda_expr = NULL_TREE;
 	  tree initializer = convert_from_reference (decl);
 
+	  /* Mark it as used now even if the use is ill-formed.  */
+	  mark_used (decl);
+
 	  /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
 	     support for an approach in which a reference to a local
 	     [constant] automatic variable in a nested class or lambda body
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-use2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-use2.C
new file mode 100644
index 0000000..695a0b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-use2.C
@@ -0,0 +1,11 @@ 
+// PR c++/50224
+// { dg-options "-std=c++0x -Wunused-parameter" }
+
+struct T;
+
+void m(T& t) // ERROR here
+{
+  [&]{
+    t; // ``t`` is referenced here
+  };
+}