diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-04-19 18:49:54 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-04-19 18:49:54 +0000 |
commit | d198067108c5306301ab067019aec518d089b6fe (patch) | |
tree | 964059415e120010e9641eff256f12b9121bd000 | |
parent | 06ff63bf1a703445008a57de038155a14792422c (diff) | |
download | gcc-d198067108c5306301ab067019aec518d089b6fe.tar.gz |
PR c++/68206 - Fix constexpr diagnostics with loops.
PR c++/68530
* constexpr.c (potential_constant_expression_1): Handle LOOP_EXPR
and GOTO_EXPR.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235217 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/constexpr-loop5.C | 19 |
3 files changed, 35 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 344cad023f7..5fb16543192 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2016-04-19 Jason Merrill <jason@redhat.com> + PR c++/68206 + PR c++/68530 + * constexpr.c (potential_constant_expression_1): Handle LOOP_EXPR + and GOTO_EXPR. + * pt.c (tsubst_expr): Remove shadowing declaration. (tsubst_pack_expansion): Add assert. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index ae0c9739d8d..d50866094d1 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4924,6 +4924,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, case NON_DEPENDENT_EXPR: /* For convenience. */ case RETURN_EXPR: + case LOOP_EXPR: + case EXIT_EXPR: return RECUR (TREE_OPERAND (t, 0), want_rval); case TRY_FINALLY_EXPR: @@ -5135,6 +5137,15 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, case EMPTY_CLASS_EXPR: return false; + case GOTO_EXPR: + { + tree *target = &TREE_OPERAND (t, 0); + /* Gotos representing break and continue are OK; we should have + rejected other gotos in parsing. */ + gcc_assert (breaks (target) || continues (target)); + return true; + } + default: if (objc_is_property_ref (t)) return false; diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-loop5.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop5.C new file mode 100644 index 00000000000..02f372d9888 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop5.C @@ -0,0 +1,19 @@ +// PR c++/68530 +// { dg-do compile { target c++14 } } + +struct thing { + void foo() {} +}; + +template<typename> +constexpr int count() +{ + auto item = thing {}; + for(; (item.foo(), false);); // { dg-error "foo" } + return 0; +} + +int main() +{ + static_assert( count<int>() == 0, "" ); // { dg-error "" } +} |