http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46371

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-12-13 
17:32:22 UTC ---
(In reply to comment #0)
>   type(foo), allocatable :: o_foo[:]

That should be "CLASS(foo)" - sorry for the typo.


TODO:

a) There is a gfc_is_coindexed() check missing for ASSOCIATE and SELECT TYPE,
cf. link and "1 INVALID" part of comment 0

b) "2 VALID" and "3 VALID" do not work:

      j = a[1]%i
           1
Error: Coarray designator at (1) but '__tmp_type_foo' is not a coarray

I think at least "attr.codimension" needs to be added during match time -
resolve time it too late. The variable is generated at select_type_set_tmp. I
tried the following (cf. select_type_set_tmp part of the patch), which does not
seem to be sufficient - though it is enough to trigger the issue in resolve.c
(cf. resolve.c part of the patch).


diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 44da1bb..6521e79 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -4531,6 +4531,8 @@ select_type_set_tmp (gfc_typespec *ts)
                              &tmp->n.sym->as, false);
       tmp->n.sym->attr.class_ok = 1;
     }
+  if (select_type_stack->selector->attr.codimension)
+    tmp->n.sym->attr.codimension = 1;
   tmp->n.sym->attr.select_type_temporary = 1;

   /* Add an association for it, so the rest of the parser knows it is
@@ -4591,8 +4593,14 @@ gfc_match_select_type (void)
   if (m != MATCH_YES)
     goto cleanup;

-  /* Check for F03:C811.  */
-  if (!expr2 && (expr1->expr_type != EXPR_VARIABLE || expr1->ref != NULL))
+  /* Check for F03:C811. Special case: scalar coarray.  */
+  if (!expr2 && (expr1->expr_type != EXPR_VARIABLE
+                || (expr1->ref != NULL
+                    && (expr1->ref->next != NULL
+                        || expr1->ref->type != REF_ARRAY
+                        || expr1->ref->u.ar.type != AR_FULL
+                        || expr1->ref->u.ar.dimen != 0
+                        || expr1->ref->u.ar.codimen != 0))))
     {
       gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
                 "use associate-name=>");
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a27fe2d..5102aea 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12121,6 +12121,7 @@ resolve_symbol (gfc_symbol *sym)
   if (((sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.coarray_comp)
        || sym->attr.codimension)
       && !(sym->attr.allocatable || sym->attr.dummy || sym->attr.save
+          || sym->attr.select_type_temporary
           || sym->ns->proc_name->attr.flavor == FL_MODULE
           || sym->ns->proc_name->attr.is_main_program
           || sym->attr.function || sym->attr.result || sym->attr.use_assoc))

Reply via email to