re PR c++/85258 (ICE with invalid range-based for-loop)
authorMarek Polacek <polacek@redhat.com>
Thu, 12 Apr 2018 20:02:47 +0000 (20:02 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 12 Apr 2018 20:02:47 +0000 (20:02 +0000)
PR c++/85258
* constexpr.c (reduced_constant_expression_p): Return false for null
trees.

* g++.dg/parse/error61.C: New test.

From-SVN: r259355

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error61.C [new file with mode: 0644]

index e9a32b0d204006225c165d9f1994e122b8325686..e3bc2d9b36e93fb130d64c9e4734ebdf5c502cde 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85258
+       * constexpr.c (reduced_constant_expression_p): Return false for null
+       trees.
+
 2018-04-11  Marek Polacek  <polacek@redhat.com>
 
        PR c++/85032
index 75f56df4465e26c91e6145e3a7df52c4155fd376..82f14baaefde1be1e8dfadf54d5ec159b2a5370c 100644 (file)
@@ -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)
index 2b4f2504e077e8191863140e2d30d5c099432185..73a358e6c1f9e139e622a9a541c232bcd983b1c5 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85258
+       * g++.dg/parse/error61.C: New test.
+
 2018-04-12  Cesar Philippidis  <cesar@codesourcery.com>
 
        * 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 (file)
index 0000000..199e1aa
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/85258
+// { dg-do compile { target c++11 } }
+
+template<int> void foo()
+{
+  int x[8];
+  for (int& i, j : x) // { dg-error "multiple" }
+    i = 0; // { dg-error "local variable" }
+}
+
+void bar()
+{
+  foo<0>();
+}