On Fri, Jan 12, 2018 at 05:09:24PM -0500, David Malcolm wrote:
> PR c++/83814 reports an ICE introduced by the location wrapper patch
> (r256448), affecting certain memset calls within templates.

Note, I think this issue sadly affects a lot of code, so it is quite urgent.

That said, wonder if we really can't do any folding when
processing_template_decl, could we e.g. do at least maybe_constant_value,
or fold if the expression is not type nor value dependent?

BTW, never know if cp_fold_rvalue is a superset of maybe_constant_value or not.

> --- a/gcc/cp/expr.c
> +++ b/gcc/cp/expr.c
> @@ -315,3 +315,25 @@ mark_exp_read (tree exp)
>      }
>  }
>  
> +/* Fold X for consideration by one of the warning functions when checking
> +   whether an expression has a constant value.  */
> +
> +tree
> +fold_for_warn (tree x)
> +{
> +  /* C++ implementation.  */
> +
> +  /* It's not generally safe to fold inside of a template, so
> +     merely strip any location wrapper and read through enum values.  */
> +  if (processing_template_decl)
> +    {
> +      STRIP_ANY_LOCATION_WRAPPER (x);
> +
> +      if (TREE_CODE (x) == CONST_DECL)
> +     x = DECL_INITIAL (x);
> +
> +      return x;
> +    }
> +
> +  return c_fully_fold (x, /*for_init*/false, /*maybe_constp*/NULL);
> +}

        Jakub

Reply via email to