diff options
author | Marek Polacek <polacek@redhat.com> | 2018-10-10 21:11:18 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2018-10-10 21:11:18 +0000 |
commit | 8e9558f029123e00008d3ef464922128d018f0fc (patch) | |
tree | fa1f1f4d7da86e9609be996a72bfb7854cd04aac /gcc/cp | |
parent | c6e8b0b3af4a2f1db9d1b13f54280c5401c53e4c (diff) | |
download | gcc-8e9558f029123e00008d3ef464922128d018f0fc.zip gcc-8e9558f029123e00008d3ef464922128d018f0fc.tar.gz gcc-8e9558f029123e00008d3ef464922128d018f0fc.tar.bz2 |
PR c++/87567 - constexpr rejects call to non-constexpr function.
* constexpr.c (potential_constant_expression_1) <case FOR_STMT>: Return
true if the condition is always false.
<case WHILE_STMT>: Likewise.
* g++.dg/cpp1y/constexpr-loop7.C: New test.
From-SVN: r265027
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 975f866..af8cb76 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-10-10 Marek Polacek <polacek@redhat.com> + + PR c++/87567 - constexpr rejects call to non-constexpr function. + * constexpr.c (potential_constant_expression_1) <case FOR_STMT>: Return + true if the condition is always false. + <case WHILE_STMT>: Likewise. + 2018-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/84423 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 403edda..4fa8c96 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5818,8 +5818,16 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, case FOR_STMT: if (!RECUR (FOR_INIT_STMT (t), any)) return false; - if (!RECUR (FOR_COND (t), rval)) + tmp = FOR_COND (t); + if (!RECUR (tmp, rval)) return false; + if (tmp) + { + if (!processing_template_decl) + tmp = cxx_eval_outermost_constant_expr (tmp, true); + if (integer_zerop (tmp)) + return true; + } if (!RECUR (FOR_EXPR (t), any)) return false; if (!RECUR (FOR_BODY (t), any)) @@ -5840,8 +5848,13 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, return true; case WHILE_STMT: - if (!RECUR (WHILE_COND (t), rval)) + tmp = WHILE_COND (t); + if (!RECUR (tmp, rval)) return false; + if (!processing_template_decl) + tmp = cxx_eval_outermost_constant_expr (tmp, true); + if (integer_zerop (tmp)) + return true; if (!RECUR (WHILE_BODY (t), any)) return false; if (breaks (jump_target) || continues (jump_target)) |