From: Marek Polacek Date: Thu, 12 Apr 2018 20:02:47 +0000 (+0000) Subject: re PR c++/85258 (ICE with invalid range-based for-loop) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4930c53ee69f18a6fd689527864d419ce0333e7a;p=gcc.git re PR c++/85258 (ICE with invalid range-based for-loop) PR c++/85258 * constexpr.c (reduced_constant_expression_p): Return false for null trees. * g++.dg/parse/error61.C: New test. From-SVN: r259355 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e9a32b0d204..e3bc2d9b36e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-04-12 Marek Polacek + + PR c++/85258 + * constexpr.c (reduced_constant_expression_p): Return false for null + trees. + 2018-04-11 Marek Polacek PR c++/85032 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 75f56df4465..82f14baaefd 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1773,6 +1773,9 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, bool reduced_constant_expression_p (tree t) { + if (t == NULL_TREE) + return false; + switch (TREE_CODE (t)) { case PTRMEM_CST: @@ -1794,9 +1797,8 @@ reduced_constant_expression_p (tree t) field = NULL_TREE; FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, idx, val) { - if (!val) - /* We're in the middle of initializing this element. */ - return false; + /* If VAL is null, we're in the middle of initializing this + element. */ if (!reduced_constant_expression_p (val)) return false; if (field) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2b4f2504e07..73a358e6c1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-12 Marek Polacek + + PR c++/85258 + * g++.dg/parse/error61.C: New test. + 2018-04-12 Cesar Philippidis * testsuite/libgomp.oacc-c-c++-common/pr84955.c: Revert 259346. diff --git a/gcc/testsuite/g++.dg/parse/error61.C b/gcc/testsuite/g++.dg/parse/error61.C new file mode 100644 index 00000000000..199e1aa721c --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error61.C @@ -0,0 +1,14 @@ +// PR c++/85258 +// { dg-do compile { target c++11 } } + +template void foo() +{ + int x[8]; + for (int& i, j : x) // { dg-error "multiple" } + i = 0; // { dg-error "local variable" } +} + +void bar() +{ + foo<0>(); +}