Commit a385474c by Marek Polacek Committed by Marek Polacek

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
parent a4e30bef
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>
......
......@@ -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;
......
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
......
// 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 ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment