diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C | 41 |
4 files changed, 64 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d4a9c67..728c501 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-02-16 Marek Polacek <polacek@redhat.com> + Jakub Jelinek <jakub@redhat.com> + + PR c++/84192 + * constexpr.c (cxx_eval_constant_expression) <case RETURN_EXPR>: Don't + set *jump_target to anything if jump_target is NULL. + 2018-02-16 Jason Merrill <jason@redhat.com> PR c++/84151 - unnecessary volatile load with static member. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 91148aa..bda9b2d 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 4329ecb..7925963 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-02-16 Marek Polacek <polacek@redhat.com> + Jakub Jelinek <jakub@redhat.com> + + PR c++/84192 + * g++.dg/cpp1y/constexpr-84192.C: New test. + 2018-02-16 Martin Sebor <msebor@redhat.com> 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 0000000..ad9458d --- /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; +} |