2014-11-18 Jason Merrill <jason@redhat.com>
+ PR c++/63925
+ * constexpr.c (cxx_eval_increment_expression): Use POINTER_PLUS_EXPR.
+
PR c++/63934
* constexpr.c (cxx_eval_call_expression): Check DECL_CONSTRUCTOR_P
rather than VOID_TYPE_P.
/* The modified value. */
bool inc = (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR);
- tree mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR,
- type, val, offset);
+ tree mod;
+ if (POINTER_TYPE_P (type))
+ {
+ /* The middle end requires pointers to use POINTER_PLUS_EXPR. */
+ offset = convert_to_ptrofftype (offset);
+ if (!inc)
+ offset = fold_build1 (NEGATE_EXPR, TREE_TYPE (offset), offset);
+ mod = fold_build2 (POINTER_PLUS_EXPR, type, val, offset);
+ }
+ else
+ mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, type, val, offset);
VERIFY_CONSTANT (mod);
/* Storing the modified value. */
// { dg-do compile { target c++14 } }
+#define SA(X) static_assert((X),#X)
constexpr int f (int i)
{
return x;
}
+constexpr int* g (int* p)
+{
+ ++p;
+ return p;
+}
+
constexpr int i = f(42);
-#define SA(X) static_assert((X),#X)
SA(i==44);
+
+int array[4];
+constexpr int* p = g(array);
+SA(p == &array[1]);