Bug 45288 - Double initialization: Warn if the value is different
Summary: Double initialization: Warn if the value is different
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 49586 (view as bug list)
Depends on:
Blocks: 33056
  Show dependency treegraph
 
Reported: 2010-08-15 16:44 UTC by Tobias Burnus
Modified: 2019-01-30 18:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-06-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-08-15 16:44:23 UTC
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
Comment 1 Dominique d'Humieres 2013-06-16 18:14:17 UTC
*** Bug 49586 has been marked as a duplicate of this bug. ***
Comment 2 Dominique d'Humieres 2013-06-16 18:15:19 UTC
*** Bug 49586 has been marked as a duplicate of this bug. ***
Comment 3 Dominique d'Humieres 2013-06-16 18:16:35 UTC
Confirmed.
Comment 4 Dominique d'Humieres 2019-01-30 18:16:05 UTC
> The following program (pasted in the #fortran IRC channel) is accepted
> by gfortran -- unless -std=f2008 is used.

% gfc pr45288.f90 -std=f95
pr45288.f90:8:25:

    8 |         PRINT '(4(4(F5.2,3H    ),/))',Matrix
      |                         1
Warning: The H format specifier at (1) is a Fortran 95 deleted feature
pr45288.f90:19:28:

   19 |         DATA Matrix(2,1)/2.0/  ! individual values
      |                            1
Error: GNU Extension: re-initialization of 'matrix' at (1)

% gfc pr45288.f90 -pedantic
pr45288.f90:19:28:

   19 |         DATA Matrix(2,1)/2.0/  ! individual values
      |                            1
Warning: GNU Extension: re-initialization of 'matrix' at (1)

since at least GGC5, closing as WORKSFORME.