PR c++/35078
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Feb 2008 10:14:57 +0000 (10:14 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Feb 2008 10:14:57 +0000 (10:14 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132424 138bc75d-0d04-0410-961f-82ee72b054a4

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 6789236..79ecec2 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 5f21574..a5bd055 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 49dd80e..44c1e3f 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 425549d..e25dfc9 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" }
+    ;
+}