https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89285

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #4)
> +      /* Preserve REINTERPRET_CAST_P.  */
> +      if (code == NOP_EXPR && REINTERPRET_CAST_P (org_x))
> +     {
> +       if (TREE_CODE (x) == NOP_EXPR && REINTERPRET_CAST_P (x))
> +         break;
> +       if (TREE_CODE (x) == NOP_EXPR)
> +         {
> +           x = copy_node (x);
> +           REINTERPRET_CAST_P (x) = 1;
> +         }
> +       else
> +         {
> +           x = build1_loc (loc, code, TREE_TYPE (x), x);
> +           REINTERPRET_CAST_P (x) = 1;
> +         }
> +     }
>        break;

Looks good, though can't we assume that if x != org_x it's a new NOP_EXPR so we
can just set REINTERPRET_CAST_P?

> and with that we reject the testcase again (like we've done in 8.x, so this
> part is [9 Regression] accepts-invalid).
> But that also means we ICE again on the:
> C bar {};

I'm not seeing this.

> So, maybe we want to ignore that:
>       if (REINTERPRET_CAST_P (t))
>         {
>           if (!ctx->quiet)
>             error_at (cp_expr_loc_or_loc (t, input_location),
>                       "a reinterpret_cast is not a constant expression");
>           *non_constant_p = true;
>           return t;
>         }
> for perhaps !ctx->manifestly_const_eval , as in when we really don't require
> constant expression.

That should depend on ctx->strict, not manifestly_const_eval.

(In reply to Jakub Jelinek from comment #7)
> Ah, so one problem is that while we save the inline bodies of functions
> before cp_fold_function, cp_fold_function is destructive and clobbers the
> saved copy.
> cp_fold itself is (hopefully) not destructive and creates new trees, but
> cp_fold_function is destructive and happily modifies the trees shared with
> something else (in this case with the constexpr funcdef table).
> 
> Jason, any preferences here?

My theory has been to switch to saving pre-gimplification bodies of constexpr
functions and doing constant evaluation using them.

Reply via email to