On Fri, Aug 16, 2019 at 06:20:20PM -0700, Jason Merrill wrote: > On 8/16/19 2:29 PM, Marek Polacek wrote: > > This patch is an attempt to fix the annoying -Wunused-but-set-* warnings > > that > > tend to occur with constexpr if. When we have something like > > > > template < typename T > > > int f(T v){ > > if constexpr(sizeof(T) == sizeof(int)){ > > return v; > > }else{ > > return 0; > > } > > } > > > > and call f('a'), then the condition is false, meaning that we won't > > instantiate > > the then-branch, as per tsubst_expr/IF_STMT: > > 17284 if (IF_STMT_CONSTEXPR_P (t) && integer_zerop (tmp)) > > 17285 /* Don't instantiate the THEN_CLAUSE. */; > > so we'll never get round to mark_exp_read-ing the decls used in the > > then-branch, causing finish_function to emit "parameter set but not used" > > warnings. > > > > It's unclear how to best deal with this. Marking the decls DECL_READ_P > > while > > parsing doesn't seem like a viable approach > > Why not?
Well, while parsing, we're in a template and so the condition won't be evaluated until tsubst_expr. So we can't tell which branch is dead. I suppose we could still mark all the _DECLs in then/else branches as read, in finish_if_stmt if IF_STMT_CONSTEXPR_P, but that seems really really ugly. -- Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA