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 e9a32b0..e3bc2d9 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 75f56df..82f14ba 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 2b4f250..73a358e 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>();
+}