We normally mark variables as used in finish_id_expression, but we
weren't doing that for variables with dependent type. They're still
used even if we don't know what type they will have when instantiated.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit b2f47a386f7f605829f4f1f30d2c1d8e254ff9d7
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Jun 15 13:32:16 2011 -0400
PR c++/49251
* semantics.c (finish_id_expression): Mark even dependent
variables as used.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 55f9519..bad7acb 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3196,7 +3196,10 @@ finish_id_expression (tree id_expression,
(or an instantiation thereof). */
if (TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (decl) == PARM_DECL)
- return convert_from_reference (decl);
+ {
+ mark_used (decl);
+ return convert_from_reference (decl);
+ }
/* The same is true for FIELD_DECL, but we also need to
make sure that the syntax is correct. */
else if (TREE_CODE (decl) == FIELD_DECL)
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic113.C b/gcc/testsuite/g++.dg/cpp0x/variadic113.C
new file mode 100644
index 0000000..3f1bb2a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic113.C
@@ -0,0 +1,20 @@
+// PR c++/49251
+// { dg-options "-std=c++0x -Wunused-parameter" }
+
+struct A {};
+template <int> int f(A);
+
+template< int... Indices >
+struct indices {};
+
+template< class... Args >
+void sink( Args&&... ) {}
+
+template< class T, int... Indices >
+void unpack_test( T && t, indices<Indices...> ) {
+ sink( f<Indices>(t)... );
+}
+
+int main() {
+ unpack_test( A(), indices<>() );
+}