2015-01-13 Jason Merrill <jason@redhat.com>
+ PR c++/64356
+ PR libstdc++/58777
+ * constexpr.c (cxx_eval_binary_expression): Don't VERIFY_CONSTANT
+ pointer expressions.
+ (cxx_eval_increment_expression): Likewise.
+
PR c++/64514
* pt.c (coerce_template_parameter_pack): Return NULL for a
zero-length fixed parameter pack with a pack expansion arg.
tree lhs, rhs;
lhs = cxx_eval_constant_expression (ctx, orig_lhs, /*lval*/false,
non_constant_p, overflow_p);
- VERIFY_CONSTANT (lhs);
+ /* Don't VERIFY_CONSTANT if this might be dealing with a pointer to
+ a local array in a constexpr function. */
+ bool ptr = POINTER_TYPE_P (TREE_TYPE (lhs));
+ if (!ptr)
+ VERIFY_CONSTANT (lhs);
rhs = cxx_eval_constant_expression (ctx, orig_rhs, /*lval*/false,
non_constant_p, overflow_p);
- VERIFY_CONSTANT (rhs);
+ if (!ptr)
+ VERIFY_CONSTANT (lhs);
location_t loc = EXPR_LOCATION (t);
enum tree_code code = TREE_CODE (t);
}
else if (cxx_eval_check_shift_p (loc, ctx, code, type, lhs, rhs))
*non_constant_p = true;
- VERIFY_CONSTANT (r);
+ if (!ptr)
+ VERIFY_CONSTANT (lhs);
return r;
}
tree val = rvalue (op);
val = cxx_eval_constant_expression (ctx, val, false,
non_constant_p, overflow_p);
- VERIFY_CONSTANT (val);
+ /* Don't VERIFY_CONSTANT if this might be dealing with a pointer to
+ a local array in a constexpr function. */
+ bool ptr = POINTER_TYPE_P (TREE_TYPE (val));
+ if (!ptr)
+ VERIFY_CONSTANT (val);
/* The modified value. */
bool inc = (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR);
}
else
mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, type, val, offset);
- VERIFY_CONSTANT (mod);
+ if (!ptr)
+ VERIFY_CONSTANT (mod);
/* Storing the modified value. */
tree store = build2 (MODIFY_EXPR, type, op, mod);
--- /dev/null
+// PR c++/64356
+// { dg-do compile { target c++14 } }
+
+typedef unsigned long size_t;
+
+template<size_t N>
+constexpr size_t f(const char (&x)[N]) {
+ size_t s = 0;
+ for(size_t c : x)
+ s += c;
+ return s;
+}
+
+template<size_t N>
+constexpr size_t g(const char (&x)[N]) {
+ char y[N] = {0};
+ for(size_t i = 0; i < N; ++i)
+ y[i] = x[i];
+ return f(y);
+}
+
+constexpr auto x = g(__DATE__);