aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constexpr.cc7
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-105050.C12
2 files changed, 18 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 778680b..9c40b05 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9439,7 +9439,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
}
}
if (flags & tf_error)
- error_at (loc, "expression %qE is not a constant expression", t);
+ {
+ if (TREE_CODE (t) == IF_STMT)
+ error_at (loc, "neither branch of %<if%> is a constant expression");
+ else
+ error_at (loc, "expression %qE is not a constant expression", t);
+ }
return false;
case VEC_INIT_EXPR:
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-105050.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-105050.C
new file mode 100644
index 0000000..e0688fb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-105050.C
@@ -0,0 +1,12 @@
+// PR c++/105050
+// { dg-do compile { target c++14 } }
+
+void g();
+void h();
+
+constexpr void f(int* p, int* q) {
+ if (p != q && *p < 0) // { dg-error "neither branch of 'if' is a constant expression" }
+ g();
+ else
+ h();
+}