]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/35078 (ICE with reference in parallel for loop)
authorJakub Jelinek <jakub@redhat.com>
Tue, 19 Feb 2008 10:14:57 +0000 (11:14 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Feb 2008 10:14:57 +0000 (11:14 +0100)
PR c++/35078
* parser.c (cp_parser_omp_for_loop): If DECL has REFERENCE_TYPE, don't
call cp_finish_decl.
* semantics.c (finish_omp_for): Fail if DECL doesn't have integral type
early.

* g++.dg/gomp/pr35078.C: New test.

From-SVN: r132424

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/gomp/pr35078.C [new file with mode: 0644]

index 6789236c031f2c99ee3b2ece54ffd3ace80748fb..79ecec280d787bbbc281e2fed7ebf5be5cacda52 100644 (file)
@@ -1,3 +1,11 @@
+2008-02-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35078
+       * parser.c (cp_parser_omp_for_loop): If DECL has REFERENCE_TYPE, don't
+       call cp_finish_decl.
+       * semantics.c (finish_omp_for): Fail if DECL doesn't have integral type
+       early.
+
 2008-02-15  Douglas Gregor  <doug.gregor@gmail.com>
 
        PR c++/35023
index 5f215742d49e7ed70a02b1d157e5078c51e848b6..a5bd05519b4e8991964b341b143775d11bf2b6aa 100644 (file)
@@ -20074,8 +20074,11 @@ cp_parser_omp_for_loop (cp_parser *parser)
 
              init = cp_parser_assignment_expression (parser, false);
 
-             cp_finish_decl (decl, NULL_TREE, /*init_const_expr_p=*/false,
-                             asm_specification, LOOKUP_ONLYCONVERTING);
+             if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE)
+               init = error_mark_node;
+             else
+               cp_finish_decl (decl, NULL_TREE, /*init_const_expr_p=*/false,
+                               asm_specification, LOOKUP_ONLYCONVERTING);
 
              if (pushed_scope)
                pop_scope (pushed_scope);
index 49dd80e17858142c06c7c33e769b4079acf0e8ce..44c1e3f319b9fbba994bccdda45ec6c8852b9dfa 100644 (file)
@@ -3903,6 +3903,16 @@ finish_omp_for (location_t locus, tree decl, tree init, tree cond,
       return NULL;
     }
 
+  if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)))
+    {
+      location_t elocus = locus;
+
+      if (EXPR_HAS_LOCATION (init))
+       elocus = EXPR_LOCATION (init);
+      error ("%Hinvalid type for iteration variable %qE", &elocus, decl);
+      return NULL;
+    }
+
   if (pre_body == NULL || IS_EMPTY_STMT (pre_body))
     pre_body = NULL;
   else if (! processing_template_decl)
index 425549de584fbb64b967f40c0913c190cf762329..e25dfc9050afd5b7059e315a66377759bdc2563e 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35078
+       * g++.dg/gomp/pr35078.C: New test.
+
 2008-02-19  Christian Bruel  <christian.bruel@st.com>
 
        * gcc.dg/packed-array.c: New testcase. 
diff --git a/gcc/testsuite/g++.dg/gomp/pr35078.C b/gcc/testsuite/g++.dg/gomp/pr35078.C
new file mode 100644 (file)
index 0000000..1f0d9ec
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/35078
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+template<int> void
+foo ()
+{
+#pragma omp parallel for
+  for (int& i = 0; i < 10; ++i)        // { dg-error "invalid type for iteration variable" }
+    ;
+}
+
+void
+bar ()
+{
+  int j = 0;
+#pragma omp parallel for
+  for (int& i = j; i < 10; ++i)        // { dg-error "invalid type for iteration variable" }
+    ;
+}