aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-10-29 19:40:18 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-10-29 19:40:18 +0000
commita385474c79d28d89861d25720715ed361e912b1a (patch)
treee4518fd6a8a63bf04eaf36911119522677b959f2
parenta4e30bef6446858bba7222afcf233c2d92e5c774 (diff)
downloadgcc-a385474c79d28d89861d25720715ed361e912b1a.zip
gcc-a385474c79d28d89861d25720715ed361e912b1a.tar.gz
gcc-a385474c79d28d89861d25720715ed361e912b1a.tar.bz2
PR c++/87594 - constexpr rejects-valid with range-based for.
* constexpr.c (potential_constant_expression_1): If the condition can't be evaluated, return true. * g++.dg/cpp1y/constexpr-loop8.C: New test. From-SVN: r265600
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C44
4 files changed, 60 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9130b86..6b9574a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-10-29 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87594 - constexpr rejects-valid with range-based for.
+ * constexpr.c (potential_constant_expression_1): If the condition
+ can't be evaluated, return true.
+
2018-10-29 Joseph Myers <joseph@codesourcery.com>
Julian Brown <julian@codesourcery.com>
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 4fa8c96..7692b17 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -5825,7 +5825,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
{
if (!processing_template_decl)
tmp = cxx_eval_outermost_constant_expr (tmp, true);
- if (integer_zerop (tmp))
+ /* If we couldn't evaluate the condition, it might not ever be
+ true. */
+ if (!integer_onep (tmp))
return true;
}
if (!RECUR (FOR_EXPR (t), any))
@@ -5853,7 +5855,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
return false;
if (!processing_template_decl)
tmp = cxx_eval_outermost_constant_expr (tmp, true);
- if (integer_zerop (tmp))
+ /* If we couldn't evaluate the condition, it might not ever be true. */
+ if (!integer_onep (tmp))
return true;
if (!RECUR (WHILE_BODY (t), any))
return false;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6cc3e1b..bfccc60 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-29 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87594 - constexpr rejects-valid with range-based for.
+ * g++.dg/cpp1y/constexpr-loop8.C: New test.
+
2018-10-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/87785
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C
new file mode 100644
index 0000000..bf132f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C
@@ -0,0 +1,44 @@
+// PR c++/87594
+// { dg-do compile { target c++14 } }
+
+constexpr bool always_false() { return false; }
+int f() { return 1; }
+
+constexpr int
+fn1()
+{
+ struct empty_range {
+ constexpr int* begin() { return 0; }
+ constexpr int* end() { return 0; }
+ } e;
+ for (auto x : e)
+ f();
+ return 0;
+}
+
+constexpr int
+fn2 ()
+{
+ int a[] = { 1, 2, 3 };
+ for (auto x : a)
+ f(); // { dg-error "call to non-.constexpr. function" }
+ return 0;
+}
+
+constexpr int
+fn3 ()
+{
+ __extension__ int a[] = { };
+ for (auto x : a)
+ f();
+ return 0;
+}
+
+
+void
+bar ()
+{
+ constexpr int i1 = fn1 ();
+ constexpr int i2 = fn2 (); // { dg-message "in .constexpr. expansion of " }
+ constexpr int i3 = fn3 ();
+}