User account creation filtered due to spam.

Bug 50438 - [F03] proc pointer to subroutine in structure constructors
Summary: [F03] proc pointer to subroutine in structure constructors
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-09-16 20:16 UTC by Daniel Franke
Modified: 2013-04-27 15:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-09-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2011-09-16 20:16:31 UTC
[http://gcc.gnu.org/ml/fortran/2011-09/msg00080.html]

The example below should be valid but is currently rejected:

$ cat procpointer.f90
  IMPLICIT NONE
  TYPE :: a
    PROCEDURE(proc), POINTER, NOPASS :: p
  END TYPE
  ABSTRACT INTERFACE
    SUBROUTINE proc
    END SUBROUTINE
  END INTERFACE
  TYPE(a), PARAMETER :: aa = a(aproc)     ! <--- 
CONTAINS
  SUBROUTINE aproc
  END SUBROUTINE
END

$ gfortran-svn -Wall -W -fimplicit-none procpointer.f90

  TYPE(a), PARAMETER :: aa = a(aproc)     ! <--- 
                                    1
Error: Symbol 'aproc' at (1) has no IMPLICIT type

$ gfortran-svn -v
gcc version 4.7.0 20110915 (experimental) (GCC)
Comment 1 janus 2011-09-17 09:39:50 UTC
On this variant I get the same error on a different line:


  IMPLICIT NONE
  TYPE :: a
    PROCEDURE(aproc), POINTER, NOPASS :: p
  END TYPE
  TYPE(a) :: aa = a(aproc)
CONTAINS
  SUBROUTINE aproc
  END SUBROUTINE
END



    PROCEDURE(aproc), POINTER, NOPASS :: p
                   1
Error: Symbol 'aproc' at (1) has no IMPLICIT type
Comment 2 janus 2011-09-17 15:00:33 UTC
Contrary to what I suggested in

http://gcc.gnu.org/ml/fortran/2011-09/msg00083.html

this problem does not seem to be specific to SUBROUTINEs. It also happens when making proc/aproc FUNCTIONS.
Comment 3 janus 2011-09-17 17:44:25 UTC
I think the problem is that the structure constructor is resolved too early (already when parsing the corresponding source line, where 'aproc' is not known yet).

Here is a simple patch to avoid this:


Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 178927)
+++ gcc/fortran/expr.c	(working copy)
@@ -2654,7 +2654,6 @@ gfc_match_init_expr (gfc_expr **result)
 {
   gfc_expr *expr;
   match m;
-  gfc_try t;
 
   expr = NULL;
 
@@ -2667,14 +2666,6 @@ gfc_match_init_expr (gfc_expr **result)
       return m;
     }
 
-  t = gfc_reduce_init_expr (expr);
-  if (t != SUCCESS)
-    {
-      gfc_free_expr (expr);
-      gfc_init_expr_flag = false;
-      return MATCH_ERROR;
-    }
-
   *result = expr;
   gfc_init_expr_flag = false;
 


It cures both test cases, but I'm pretty sure it will have quite a number of testsuite failures (haven't checked yet). If we remove it here, 'gfc_reduce_init_expr' should be called somewhere at resolution stage, of course! We just need a suitable place for doing this ...
Comment 4 janus 2011-09-17 17:53:01 UTC
(In reply to comment #3)
> I think the problem is that the structure constructor is resolved too early

Btw, there was a similar problem recently (PR 49112 comment 6), which was fixed by this patch:

http://gcc.gnu.org/ml/fortran/2011-07/msg00305.html
Comment 5 janus 2013-04-27 11:33:29 UTC
(In reply to comment #3)
> Here is a simple patch to avoid this:
>
> [...]
>
> It cures both test cases, but I'm pretty sure it will have quite a number of
> testsuite failures (haven't checked yet).

The patch from comment #3 indeed shows a huge number of failures (as expected).


> If we remove it here,
> 'gfc_reduce_init_expr' should be called somewhere at resolution stage, of
> course! We just need a suitable place for doing this ...

e.g. something like 'resolve_values' or 'resolve_structure_cons'?


However, I'm thinking that this approach may be too big of a hammer for the problem at hand. A somewhat less invasive patch:

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 198155)
+++ gcc/fortran/expr.c	(working copy)
@@ -2522,6 +2522,8 @@ gfc_check_init_expr (gfc_expr *e)
 
 	  break;
 	}
+      else if (e->symtree->n.sym->attr.flavor == FL_PROCEDURE)
+	break;
 
       if (gfc_in_match_data ())
 	break;


This is also sufficient to remove the error. Regtesting now ...
Comment 6 janus 2013-04-27 15:31:29 UTC
(In reply to comment #5)
> This is also sufficient to remove the error. Regtesting now ...

The patch in comment 5 regtests cleanly. However, it only fixes comment 1 but not comment 0.