IMPORT fails, if one imports the same symbol in multiple interface bodies of
same interface block.

Found by Christopher D. Rickett,
http://gcc.gnu.org/ml/fortran/2007-02/msg00466.html

Test case:
--------------------------------------------
module test_import
  implicit none

  type :: my_type
     integer :: data
  end type my_type

  interface
     integer function func1(param)
       import :: my_type
       type(my_type) :: param
     end function func1

     integer function func2(param)
       import :: my_type
       type(my_type), value :: param
     end function func2
  end interface
end module test_import
--------------------------------------------

Error message:

     integer function func1(param)
                                1
test_import.f03:4.17:

  type :: my_type
                2
Error: The type my_type cannot be host associated at (1) because it is
blocked by an incompatible object of the same name at (2)


Simple fix:
------------------------------
Index: resolve.c
===================================================================
--- resolve.c   (revision 122189)
+++ resolve.c   (working copy)
@@ -5656,7 +5656,8 @@
   /* Check to see if a derived type is blocked from being host associated
      by the presence of another class I symbol in the same namespace.
      14.6.1.3 of the standard and the discussion on comp.lang.fortran.  */
-  if (sym->ts.type == BT_DERIVED && sym->ns != sym->ts.derived->ns)
+  if (sym->ts.type == BT_DERIVED && sym->ns != sym->ts.derived->ns
+      && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY)
     {
       gfc_symbol *s;
       gfc_find_symbol (sym->ts.derived->name, sym->ns, 0, &s);
------------------------------

Currently, "IMPORT :: symbol" copies the symbol like follows (simplified code;
decl.c, gfc_match_import):
-------------------
          gfc_find_symbol (name, gfc_current_ns->parent, 1, &sym)

          st = gfc_new_symtree (&gfc_current_ns->sym_root, name);
          st->n.sym = sym;
          sym->refs++;
          sym->ns = gfc_current_ns;
-------------------

Possible implementation alternative, suggested by Paul Thomas,
http://gcc.gnu.org/ml/fortran/2007-02/msg00484.html

> alternatively, I have wondered for a long time if
> int ambiguous; in gfc_symtree is not out-of-order extravigant?
> A bit-field, like symbol_attribute might be very useful. Needless to say,
> imported could be added to ambiguous.

If we change the implementation, we could re-add
http://gcc.gnu.org/viewcvs/trunk/gcc/fortran/trans-decl.c?r1=119412&r2=119651&pathrev=119651&diff_format=h
cf. PR 27546.


-- 
           Summary: IMPORT fails for same symbol in multiple interface
                    bodies of same interface block
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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

Reply via email to