When we are building up a call by hand at low level, apparently we need
to explicitly mark the arguments as read. Or unset TREE_USED, I
suppose, but they are in fact read.
Tested x86_64-pc-linux-gnu, applied to trunk and 4.6.1.
commit dec88b99a5f96603df3518da6b108e058613bc2d
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue Jun 21 20:07:45 2011 +0000
PR c++/49482
* semantics.c (maybe_add_lambda_conv_op): Call mark_exp_read for
static fn parameters.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175273 138bc75d-0d04-0410-961f-82ee72b054a4
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 594d239..6622de6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8780,7 +8780,10 @@ maybe_add_lambda_conv_op (tree type)
argvec = make_tree_vector ();
VEC_quick_push (tree, argvec, arg);
for (arg = DECL_ARGUMENTS (statfn); arg; arg = DECL_CHAIN (arg))
- VEC_safe_push (tree, gc, argvec, arg);
+ {
+ mark_exp_read (arg);
+ VEC_safe_push (tree, gc, argvec, arg);
+ }
call = build_call_a (callop, VEC_length (tree, argvec),
VEC_address (tree, argvec));
CALL_FROM_THUNK_P (call) = 1;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-warn3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-warn3.C
new file mode 100644
index 0000000..77f35bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-warn3.C
@@ -0,0 +1,12 @@
+// PR c++/49482
+// { dg-options "-std=c++0x -Wunused-but-set-parameter" }
+
+template<class T>
+void f() {
+ []( bool b ){ return b; };
+}
+
+int main()
+{
+ f<int>();
+}