aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-03-01 21:32:44 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-03-01 21:32:44 -0500
commitc8a66fc97b4c4167bfc71a5017d61e7ed51d4177 (patch)
treeef8fe75c7a05fccb20d3e94e4e0ae583d3f2e8fa /gcc
parent7f0e23e931064d8e8758e01d95bfb89b8fa32e6e (diff)
downloadgcc-c8a66fc97b4c4167bfc71a5017d61e7ed51d4177.zip
gcc-c8a66fc97b4c4167bfc71a5017d61e7ed51d4177.tar.gz
gcc-c8a66fc97b4c4167bfc71a5017d61e7ed51d4177.tar.bz2
re PR c++/51489 (constexpr not working consistently)
PR c++/51489 * constexpr.c (cxx_eval_binary_expression): Don't VERIFY_CONSTANT the operands. From-SVN: r233878
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/constexpr.c16
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-array4.C12
3 files changed, 25 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3a24cc9..e8be35d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2016-03-01 Jason Merrill <jason@redhat.com>
+ PR c++/51489
+ * constexpr.c (cxx_eval_binary_expression): Don't VERIFY_CONSTANT
+ the operands.
+
PR c++/69995
* constexpr.c (cxx_eval_call_expression): Unshare arg.
(cxx_eval_constant_expression) [DECL_EXPR]: Unshare init.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index a21997a..bcb129f 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1612,15 +1612,14 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
tree lhs, rhs;
lhs = cxx_eval_constant_expression (ctx, orig_lhs, /*lval*/false,
non_constant_p, overflow_p);
- /* 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);
+ /* Don't VERIFY_CONSTANT here, it's unnecessary and will break pointer
+ subtraction. */
+ if (*non_constant_p)
+ return t;
rhs = cxx_eval_constant_expression (ctx, orig_rhs, /*lval*/false,
non_constant_p, overflow_p);
- if (!ptr)
- VERIFY_CONSTANT (rhs);
+ if (*non_constant_p)
+ return t;
location_t loc = EXPR_LOCATION (t);
enum tree_code code = TREE_CODE (t);
@@ -1653,6 +1652,9 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
}
else if (cxx_eval_check_shift_p (loc, ctx, code, type, lhs, rhs))
*non_constant_p = true;
+ /* 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 (r);
return r;
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-array4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-array4.C
new file mode 100644
index 0000000..fc01047
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-array4.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++14 } }
+
+constexpr bool g()
+{
+ int ar[4] = { 1, 2, 3, 4 };
+ auto e1 = ar;
+ auto e4 = ar+3;
+ return (e4-e1) == 3;
+}
+
+#define SA(X) static_assert((X),#X)
+SA(g());