public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45288]  New: Double initialization: Warn if the value is different
@ 2010-08-15 16:44 burnus at gcc dot gnu dot org
  0 siblings, 0 replies; only message in thread
From: burnus at gcc dot gnu dot org @ 2010-08-15 16:44 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-15 16:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-15 16:44 [Bug fortran/45288] New: Double initialization: Warn if the value is different burnus at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).