https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95307
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I've tried:
--- gcc/cp/constexpr.c.jj 2020-05-25 10:06:59.886175941 +0200
+++ gcc/cp/constexpr.c 2020-05-26 22:02:23.661355854 +0200
@@ -6196,6 +6196,18 @@ cxx_eval_constant_expression (const cons
if (VOID_TYPE_P (type))
return void_node;
+ if (CONVERT_EXPR_CODE_P (TREE_CODE (t))
+ && ARITHMETIC_TYPE_P (type)
+ && INDIRECT_TYPE_P (TREE_TYPE (op)))
+ {
+ if (!ctx->quiet)
+ error ("conversion from pointer type %qT "
+ "to arithmetic type %qT in a constant expression",
+ TREE_TYPE (op), type);
+ *non_constant_p = true;
+ return t;
+ }
+
if (TREE_CODE (op) == PTRMEM_CST && !TYPE_PTRMEM_P (type))
op = cplus_expand_constant (op);
@@ -6797,19 +6809,6 @@ cxx_eval_outermost_constant_expr (tree t
non_constant_p = true;
}
- /* 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;
- }
if (!non_constant_p && overflow_p)
non_constant_p = true;
but will need to look through testsuite regressions and find out which tests
just need adjustments and if there isn't something really broken by that.