aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/constexpr.cc12
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C15
2 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index c3ee970..94b54fc 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6234,6 +6234,18 @@ cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t,
offset = fold_build1 (NEGATE_EXPR, TREE_TYPE (offset), offset);
mod = fold_build2 (POINTER_PLUS_EXPR, type, val, offset);
}
+ else if (c_promoting_integer_type_p (type)
+ && !TYPE_UNSIGNED (type)
+ && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
+ {
+ offset = fold_convert (integer_type_node, offset);
+ mod = fold_convert (integer_type_node, val);
+ tree t = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, integer_type_node,
+ mod, offset);
+ mod = fold_convert (type, t);
+ if (TREE_OVERFLOW_P (mod) && !TREE_OVERFLOW_P (t))
+ TREE_OVERFLOW (mod) = false;
+ }
else
mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, type, val, offset);
if (!ptr)
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C
new file mode 100644
index 0000000..8ca6fce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C
@@ -0,0 +1,15 @@
+// PR c++/105774
+// { dg-do compile { target c++14 } }
+
+constexpr signed char
+foo ()
+{
+#if __SCHAR_MAX__ < __INT_MAX__
+ signed char x = __SCHAR_MAX__;
+#else
+ signed char x = 0;
+#endif
+ return ++x;
+}
+
+constexpr auto a = foo ();