Bug 40451 - [F03] procedure pointer assignment rejected
Summary: [F03] procedure pointer assignment rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-06-15 21:09 UTC by Tobias Burnus
Modified: 2009-06-18 08:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-06-17 09:26:05


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-06-15 21:09:58 UTC
The following program is rejected with:

    f => sin
         1
Error: Interfaces don't match in procedure pointer assignment at (1)

However, if one removes the "module m; contains" it is accepted


module m
contains
  function f()
    intrinsic :: sin
    procedure(sin), pointer :: f
    f => sin
  end function f
end module m
Comment 1 Tobias Burnus 2009-06-15 21:10:51 UTC
Post script: With your current patch, the error message is:

Error: Interface mismatch in procedure pointer assignment at (1): 'sin' has the wrong number of arguments
Comment 2 janus 2009-06-17 08:33:57 UTC
The test case is also rejected without being inside a module:

contains
  function f()
    intrinsic :: sin
    procedure(sin), pointer :: f
    f => sin
  end function f
end

However, if the 'contains' is removed, it is accepted.
Comment 3 janus 2009-06-17 08:54:23 UTC
The error also goes away if 'implicit none' is inserted.
Comment 4 janus 2009-06-17 09:26:05 UTC
Mine. Here's a patch:

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(revision 148518)
+++ gcc/fortran/symbol.c	(working copy)
@@ -317,7 +317,7 @@ gfc_check_function_type (gfc_namespace *
   if (!proc->attr.contained || proc->result->attr.implicit_type)
     return;
 
-  if (proc->result->ts.type == BT_UNKNOWN)
+  if (proc->result->ts.type == BT_UNKNOWN && proc->result->ts.interface == NULL)
     {
       if (gfc_set_default_type (proc->result, 0, gfc_current_ns)
 		== SUCCESS)
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 148519)
+++ gcc/fortran/resolve.c	(working copy)
@@ -347,7 +347,7 @@ resolve_contained_fntype (gfc_symbol *sy
     return;
 
   /* Try to find out of what the return type is.  */
-  if (sym->result->ts.type == BT_UNKNOWN)
+  if (sym->result->ts.type == BT_UNKNOWN && sym->result->ts.interface == NULL)
     {
       t = gfc_set_default_type (sym->result, 0, ns);
Comment 5 janus 2009-06-18 08:09:56 UTC
Subject: Bug 40451

Author: janus
Date: Thu Jun 18 08:09:40 2009
New Revision: 148652

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148652
Log:
2009-06-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40451
	* resolve.c (resolve_contained_fntype): Prevent implicit typing for
	procedures with explicit interface.
	* symbol.c (gfc_check_function_type): Ditto.

2009-06-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40451
	* gfortran.dg/proc_ptr_result_4.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_4.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 janus 2009-06-18 08:13:12 UTC
Fixed with r148652. Closing.