Bug 44614 - [OOP] Wrongly importing a symbol into an interface without IMPORT
Summary: [OOP] Wrongly importing a symbol into an interface without IMPORT
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks:
 
Reported: 2010-06-21 16:39 UTC by Tobias Burnus
Modified: 2010-06-24 08:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-21 18:00:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-06-21 16:39:02 UTC
Based on a report by bd satish at http://gcc.gnu.org/ml/fortran/2010-06/msg00210.html

The following program is invalid as IMPORT is missing, but gfortran still compiles it:

Expected: An error such as:
  Error: line 12: SELF is of undefined derived type CONNECTION
or
  error #6457: This derived type name has not been declared.   [CONNECTION]


module factory_pattern
implicit none

type, abstract :: Connection
    contains
    procedure(generic_desc), deferred :: description
end type Connection

abstract interface
    subroutine generic_desc(self)
!        import
        class(Connection) :: self
    end subroutine generic_desc
end interface
end module factory_pattern
Comment 1 Tobias Burnus 2010-06-21 16:44:15 UTC
Cf. also PR 44616 for the ICE reported at the mailing list.
Comment 2 janus 2010-06-21 18:00:04 UTC
Confirmed. Changing the CLASS statement into TYPE gives the correct error:

        type(Connection) :: self
                                1
Error: the type of 'self' at (1) has not been declared within the interface
Comment 3 Tobias Burnus 2010-06-22 21:01:40 UTC
Simple patch. Janus, if you have time, you can create a full patch out of it.

Index: decl.c
===================================================================
--- decl.c      (revision 161227)
+++ decl.c      (working copy)
@@ -1764,7 +1764,7 @@ variable_decl (int elem)
      specified in the procedure definition, except that the interface
      may specify a procedure that is not pure if the procedure is
      defined to be pure(12.3.2).  */
-  if (current_ts.type == BT_DERIVED
+  if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
       && gfc_current_ns->proc_name
       && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY
       && current_ts.u.derived->ns != gfc_current_ns)
Comment 4 Tobias Burnus 2010-06-24 07:51:37 UTC
Subject: Bug 44614

Author: burnus
Date: Thu Jun 24 07:51:22 2010
New Revision: 161310

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161310
Log:
2010-06-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/44614
        * decl.c (variable_decl): Fix IMPORT diagnostic for CLASS.

2010-06-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/44614
        * gfortran.dg/import8.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/import8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Tobias Burnus 2010-06-24 08:01:03 UTC
FIXED on the trunk (4.6).