public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/45288]  New: Double initialization: Warn if the value is different
Date: Sun, 15 Aug 2010 16:44:00 -0000	[thread overview]
Message-ID: <bug-45288-13404@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2010-08-15 16:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-45288-13404@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).