On Mon, Jan 18, 2016 at 11:17:04AM -0500, Jason Merrill wrote: > But we do currently print > > wa.C:1:24: warning: unused parameter ‘xs#0’ [-Wunused-parameter] > wa.C:1:24: warning: unused parameter ‘xs#1’ [-Wunused-parameter] > wa.C:1:24: warning: unused parameter ‘xs#2’ [-Wunused-parameter] > > for that testcase, and I think your patch would remove this warning as well.
Right. How about this instead? In this version, I only set TREE_USED when we actually use the pack, so we'll keep the warning for the testcase above. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-01-19 Marek Polacek <pola...@redhat.com> PR c++/68965 * pt.c (tsubst_copy): Mark elements in expanded vector as used. * g++.dg/cpp1y/parameter-pack-1.C: New test. * g++.dg/cpp1y/parameter-pack-2.C: New test. diff --git gcc/cp/pt.c gcc/cp/pt.c index 866b4b1..6062ebe 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -14010,7 +14010,12 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) --c_inhibit_evaluation_warnings; if (TREE_CODE (expanded) == TREE_VEC) - len = TREE_VEC_LENGTH (expanded); + { + len = TREE_VEC_LENGTH (expanded); + /* Set TREE_USED for the benefit of -Wunused. */ + for (int i = 0; i < len; i++) + TREE_USED (TREE_VEC_ELT (expanded, i)) = true; + } if (expanded == error_mark_node) return error_mark_node; diff --git gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C index e69de29..27a6bf9 100644 --- gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C +++ gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C @@ -0,0 +1,23 @@ +// PR c++/68965 +// { dg-do compile { target c++14 } } +// { dg-options "-Wall -Wextra" } + +auto count = [](auto&&... xs) +{ + return sizeof...(xs); +}; + +struct count_struct +{ + template<typename... Ts> + auto operator()(Ts&&... xs) + { + return sizeof...(xs); + } +}; + +int main() +{ + count(1,2,3); + count_struct{}(1,2,3); +} diff --git gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C index e69de29..9520875 100644 --- gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C +++ gcc/testsuite/g++.dg/cpp1y/parameter-pack-2.C @@ -0,0 +1,21 @@ +// PR c++/68965 +// { dg-do compile { target c++14 } } +// { dg-options "-Wall -Wextra" } + +auto count = [](auto&&... xs) // { dg-warning "unused parameter" } +{ +}; + +struct count_struct +{ + template<typename... Ts> + auto operator()(Ts&&... xs) // { dg-warning "unused parameter" } + { + } +}; + +int main() +{ + count(1,2,3); + count_struct{}(1,2,3); +} Marek