+2018-06-15 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/86093
+ * c-typeck.c (pointer_diff): Cast both pointers to unqualified types
+ before doing POINTER_DIFF_EXPR.
+
2018-06-07 Marek Polacek <polacek@redhat.com>
PR c/85318
op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
convert (inttype, op1), false);
else
- op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
+ {
+ /* Cast away qualifiers. */
+ op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
+ op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
+ op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
+ }
/* This generates an error if op1 is pointer to incomplete type. */
if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))