Message ID | 20160113165022.GK25528@redhat.com |
---|---|
State | New |
Headers | show |
On 01/13/2016 11:50 AM, Marek Polacek wrote: > So to quash that -Wunused-parameter warning, I decided to set TREE_USED at the > place where we create those #xs parameters. Won't that cause false negatives when the parameter pack is never mentioned in the function? Jason
On Wed, Jan 13, 2016 at 03:33:27PM -0500, Jason Merrill wrote: > On 01/13/2016 11:50 AM, Marek Polacek wrote: > >So to quash that -Wunused-parameter warning, I decided to set TREE_USED at the > >place where we create those #xs parameters. > > Won't that cause false negatives when the parameter pack is never mentioned > in the function? You mean that e.g. for auto fn = [](auto&&... xs) { }; int main () { fn (1, 2, 3); } we won't print z.cc:1:24: warning: unused parameter 'xs' [-Wunused-parameter] anymore? Unfortunately, we don't print that even without the patch :(. Marek
On 01/13/2016 05:52 PM, Marek Polacek wrote: > On Wed, Jan 13, 2016 at 03:33:27PM -0500, Jason Merrill wrote: >> On 01/13/2016 11:50 AM, Marek Polacek wrote: >>> So to quash that -Wunused-parameter warning, I decided to set TREE_USED at the >>> place where we create those #xs parameters. >> >> Won't that cause false negatives when the parameter pack is never mentioned >> in the function? > > You mean that e.g. for > > auto fn = [](auto&&... xs) > { > }; > > int > main () > { > fn (1, 2, 3); > } > > we won't print > z.cc:1:24: warning: unused parameter 'xs' [-Wunused-parameter] > anymore? Unfortunately, we don't print that even without the patch :(. 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. Jason
diff --git gcc/cp/pt.c gcc/cp/pt.c index edec774..b9d4f59 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -11924,6 +11924,9 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) /* Rename the parameter to include the index. */ DECL_NAME (r) = make_ith_pack_parameter_name (DECL_NAME (r), i); + + /* Set TREE_USED for the benefit of -Wunused. */ + TREE_USED (r) = true; } else if (!type) /* We're dealing with a normal parameter. */ diff --git gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C gcc/testsuite/g++.dg/cpp1y/parameter-pack-1.C index e69de29..8119b6e 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,4,5,6,7); + count_struct{}(1,2,3,4,5,6,7); +}