Bug 51266

Summary: [F08] Pointer initialization in PARAMETER
Product: gcc Reporter: Tobias Burnus <burnus>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: janus
Priority: P3 Keywords: rejects-valid
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on: 45290    
Bug Blocks:    

Description Tobias Burnus 2011-11-22 08:50:37 UTC
The following program from
   http://groups.google.com/group/comp.lang.fortran/msg/38bbc52c641f4b13
is rejected with:

        TYPE(T), PARAMETER :: C = T(X)  !!!
                                    1
  Error: Parameter 'x' at (1) has not been declared or is a variable, which
  does not reduce to a constant expression

The check is wrong as one has a pointer initialization - and X is a valid REAL, TARGET, SAVE variable. Without PARAMETER, the initialization works. I think just the checking needs to be fixed. (Note this is a F2008 feature.)

Variant: Use "T()" an in the derived type  "P => X".


      PROGRAM MAIN
        TARGET X
        DATA X/0.0/
        TYPE T
          REAL, POINTER :: P
        END TYPE
        TYPE(T), PARAMETER :: C = T(X)  !!!
        READ *, X
        CALL SUBR()
      CONTAINS
        SUBROUTINE SUBR
          REAL, PARAMETER :: Y = C%P  !!!
         PRINT *, Y
        END SUBROUTINE
      END
Comment 1 Tobias Burnus 2011-11-22 15:44:34 UTC
Hmm, I somehow have the feeling that encountered this bug already. See the thread starting at http://j3-fortran.org/pipermail/j3/2011-November/004840.html

I think I concur with Malcolm that the code of comment 0 cannot be implemented (at least not without combining the linker with the front-end compiler, something no one wants to do):
  http://j3-fortran.org/pipermail/j3/2011-November/004851.html

On the other hand, I think Bob right at
  http://j3-fortran.org/pipermail/j3/2011-November/004857.html
that the current standard seems to have a loop hole.

I probably should have realized the discussion earlier - on the other hand, Bob seems to insist (cf. link above) that the program is not only valid but should also be valid - otherwise, I presume, he wouldn't have posted it at comp.lang.fortran.

(A PR might already exist for this thread.)
Comment 2 janus 2012-04-15 19:55:22 UTC
(In reply to comment #1)
> (A PR might already exist for this thread.)

Well, there is PR 45290 and PR 50410 comment 9, which are at least related.
Comment 3 janus 2012-04-15 20:03:47 UTC
(In reply to comment #2)
> > (A PR might already exist for this thread.)
> 
> Well, there is PR 45290 and PR 50410 comment 9, which are at least related.

And moreover there is PR 51076, which is really identical to this one.