The following program (pasted in the #fortran IRC channel) is accepted by
gfortran -- unless -std=f2008 is used.

Expected: By default a warning (or error) is printed - if two different values
are used. Maybe one should reject the program altogether - or allow it only
with -std=legacy. -- The program can too easily produce indented results (cf.
below).

However, I think one can still allow double initialization of the same value
with -std=gnu and without a warning.

Without a warning (or better error) one can easily miss unintended double
initializations - e.g. in legacy programs. Additionally, the result of such an
initialization by different values is completely arbitrary as the program below
shows. As variant, one can swap the whole-array initialization ("prefill") with
the "individual values".

ifort always prints "-1" independent of the order, Pathscale seemingly does
what the user intended - the initially set "-1" is later overridden. While
gfortran keeps the initial value, i.e. prints "-1" for the program below but
the "intended" result if one swaps the order.

      PROGRAM Foo
C COMMON Variables
        PARAMETER (MatDim=4)
        PARAMETER (MatMax=MatDim**2)
        DOUBLE PRECISION Matrix(MatDim,MatDim)
        COMMON /CNMatrix/ Matrix
        PRINT *,'Matrix:'
        PRINT '(4(4(F5.2,3H    ),/))',Matrix
      END

      BLOCK DATA MatrixData
C COMMON Variables
        PARAMETER (MatDim=4)
        PARAMETER (MatMax=MatDim**2)
        DOUBLE PRECISION Matrix(MatDim,MatDim)
        COMMON /CNMatrix/ Matrix

        DATA Matrix/MatMax*-1.0/  ! prefill
        DATA Matrix(2,1)/2.0/  ! individual values
        DATA Matrix(1,2)/3.0/  ! individual values
      END


-- 
           Summary: Double initialization: Warn if the value is different
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          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=45288

Reply via email to