From 019e0ae8e00068d14aeee7c3b9e54ec14d2a5dd9 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 16 Feb 2018 22:38:53 +0000 Subject: [PATCH] re PR c++/84192 (ICE with statement expression) PR c++/84192 * constexpr.c (cxx_eval_constant_expression) : Don't set *jump_target to anything if jump_target is NULL. * g++.dg/cpp1y/constexpr-84192.C: New test. Co-Authored-By: Jakub Jelinek From-SVN: r257770 --- gcc/cp/ChangeLog | 7 ++++ gcc/cp/constexpr.c | 11 +++++- gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C | 41 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d4a9c67d2ec..728c501ad55 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-02-16 Marek Polacek + Jakub Jelinek + + PR c++/84192 + * constexpr.c (cxx_eval_constant_expression) : Don't + set *jump_target to anything if jump_target is NULL. + 2018-02-16 Jason Merrill PR c++/84151 - unnecessary volatile load with static member. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 91148aa8d72..bda9b2d211e 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4254,7 +4254,16 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, non_constant_p, overflow_p); - *jump_target = t; + if (jump_target) + *jump_target = t; + else + { + /* Can happen with ({ return true; }) && false; passed to + maybe_constant_value. There is nothing to jump over in this + case, and the bug will be diagnosed later. */ + gcc_assert (ctx->quiet); + *non_constant_p = true; + } break; case SAVE_EXPR: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4329ecbd76e..79259637f21 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-02-16 Marek Polacek + Jakub Jelinek + + PR c++/84192 + * g++.dg/cpp1y/constexpr-84192.C: New test. + 2018-02-16 Martin Sebor PR c++/79064 diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C new file mode 100644 index 00000000000..ad9458d238f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C @@ -0,0 +1,41 @@ +// PR c++/84192 +// { dg-do compile { target c++14 } } +// { dg-options "" } + +bool +f1 () +{ + return ({ return true; }) && false; // { dg-error "could not convert" } +} + +void +f2 () +{ + for (;;) + constexpr bool b = ({ break; false; }) && false; // { dg-error "statement is not a constant expression" } +} + +constexpr bool +f3 (int n) +{ + bool b = false; + for (int i = 0; i < n; i++) + b = ({ break; }); // { dg-error "void value not ignored as it ought to be" } + return b; +} + +constexpr bool b = f3 (4); + +bool +f4 () +{ + constexpr bool b = ({ return true; }) && false; // { dg-error "could not convert" } + return false; +} + +constexpr bool +f5 (int x) +{ + constexpr bool b = ({ switch (x) case 0: true; }) && false; // { dg-error "could not convert" } + return false; +} -- 2.30.2