https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95307
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For - 0 it is diagnosed by:
/* Technically we should check this for all subexpressions, but that
runs into problems with our internal representation of pointer
subtraction and the 5.19 rules are still in flux. */
if (CONVERT_EXPR_CODE_P (TREE_CODE (r))
&& ARITHMETIC_TYPE_P (TREE_TYPE (r))
&& TREE_CODE (TREE_OPERAND (r, 0)) == ADDR_EXPR)
{
if (!allow_non_constant)
error ("conversion from pointer type %qT "
"to arithmetic type %qT in a constant expression",
TREE_TYPE (TREE_OPERAND (r, 0)), TREE_TYPE (r));
non_constant_p = true;
}
and what matters is what the comment says, we really should be checking it for
subexpressions (therefore move into cxx_eval_constant_expression in
NOP_EXPR/CONVERT_EXPR case).
We have POINTER_DIFF_EXPR now so one would hope we don't run into the issues
mentioned there.