Message ID | 20100908081051.GM1269@tyan-ft48-01.lab.bos.redhat.com |
---|---|
State | New |
Headers | show |
On 09/08/2010 04:10 AM, Jakub Jelinek wrote: > Attached are two alternative patches to fix the attached testcase. > For non-templates a similar issue has been fixed before by calling > mark_rvalue_use in compute_array_index_type, but, but for templates > the const var is changed for an INTEGER_CST already before it reaches > that function, by fold_decl_constant_value. I have no idea when > fold_decl_constant_value actually needs to loop, perhaps just the > second patch should be sufficient (it is for the testcase, and also Let's go with the second patch. My constexpr work is doing away with fold_decl_constant_value, anyway. Jason
--- gcc/cp/pt.c.jj 2010-09-06 08:41:35.000000000 +0200 +++ gcc/cp/pt.c 2010-09-08 09:11:28.000000000 +0200 @@ -4854,6 +4854,7 @@ fold_decl_constant_value (tree expr) do { expr = fold_non_dependent_expr (const_expr); + expr = mark_rvalue_use (expr); const_expr = integral_constant_value (expr); } while (expr != const_expr); --- gcc/testsuite/g++.dg/warn/Wunused-var-15.C.jj 2010-09-08 09:32:24.000000000 +0200 +++ gcc/testsuite/g++.dg/warn/Wunused-var-15.C 2010-09-08 09:31:44.000000000 +0200 @@ -0,0 +1,29 @@ +// PR c++/45588 +// { dg-do compile } +// { dg-options "-Wunused" } + +void bar (unsigned char *); + +template <int N> +struct S +{ + static const int k = 6; +}; + +template <int N> +const int S<N>::k; + +template <int N> +void +foo () +{ + const int i = S<N>::k; + unsigned char a[i]; + bar (a); +} + +void +baz () +{ + foo<0> (); +}