+2016-06-08 Jakub Jelinek <jakub@redhat.com>
+ Richard Biener <rguenther@suse.de>
+
+ PR c++/71448
+ * fold-const.c (fold_comparison): Handle CONSTANT_CLASS_P (base0)
+ the same as DECL_P (base0) for indirect_base0. Use equality_code
+ in one further place.
+
2016-06-08 Richard Sandiford <richard.sandiford@arm.com>
* expmed.c (store_bit_field_1): Do not restrict a multiword op0
if ((offset0 == offset1
|| (offset0 && offset1
&& operand_equal_p (offset0, offset1, 0)))
- && (code == EQ_EXPR
- || code == NE_EXPR
- || (indirect_base0 && DECL_P (base0))
+ && (equality_code
+ || (indirect_base0
+ && (DECL_P (base0) || CONSTANT_CLASS_P (base0)))
|| POINTER_TYPE_OVERFLOW_UNDEFINED))
{
6.5.6/8 and /9 with respect to the signed ptrdiff_t. */
else if (bitpos0 == bitpos1
&& (equality_code
- || (indirect_base0 && DECL_P (base0))
+ || (indirect_base0
+ && (DECL_P (base0) || CONSTANT_CLASS_P (base0)))
|| POINTER_TYPE_OVERFLOW_UNDEFINED))
{
/* By converting to signed sizetype we cover middle-end pointer
--- /dev/null
+// PR c++/71448
+// { dg-do compile }
+// { dg-additional-options "-std=c++11" }
+
+static constexpr const char foo[] = "foo";
+static constexpr const char *bar = "bar";
+
+static_assert ((foo + 3 - foo) == 3, "check");
+static_assert (foo + 2 != foo, "check");
+static_assert (foo + 2 >= foo, "check");
+static_assert (3 + foo >= foo, "check");
+static_assert (foo <= foo + 2, "check");
+static_assert (foo <= 3 + foo, "check");
+static_assert (foo + 2 > foo, "check");
+static_assert (3 + foo > foo, "check");
+static_assert (foo < 2 + foo, "check");
+static_assert (foo < foo + 3, "check");
+static_assert ((bar + 3 - bar) == 3, "check");
+static_assert (bar + 2 != bar, "check");
+static_assert (2 + bar >= bar, "check");
+static_assert (bar + 3 >= bar, "check");
+static_assert (bar <= bar + 2, "check");
+static_assert (bar <= 3 + bar, "check");
+static_assert (bar + 2 > bar, "check");
+static_assert (3 + bar > bar, "check");
+static_assert (bar < 2 + bar, "check");
+static_assert (bar < bar + 3, "check");