diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-18 19:09:55 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-18 19:09:55 +0000 |
commit | c8a8f7ad84c47b51155d139745e26ffa0f4fb9e1 (patch) | |
tree | 22d1fcaf625bb8242c9bdcfce0bbeb522fbd196d /gcc | |
parent | b85cb8b28e2ce0c1965aa393233da720fdf938e6 (diff) | |
download | gcc-c8a8f7ad84c47b51155d139745e26ffa0f4fb9e1.tar.gz |
PR c++/63925
* constexpr.c (cxx_eval_increment_expression): Use POINTER_PLUS_EXPR.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217731 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C | 12 |
3 files changed, 25 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 28d8796842d..0628b4221d9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 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. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 4325caa0672..5abea14ae39 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2566,8 +2566,17 @@ cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t, /* 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. */ diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C index 2b099c821e0..ecd7c047c85 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C @@ -1,4 +1,5 @@ // { dg-do compile { target c++14 } } +#define SA(X) static_assert((X),#X) constexpr int f (int i) { @@ -8,6 +9,15 @@ 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]); |