------- Comment #1 from burnus at gcc dot gnu dot org 2007-11-25 21:20 -------
That error message disappears with the patch to PR 33152.
>From "5.5.2.4 Differences between named common and blank common":
"A data object in a named common block may be initially defined by means of a
DATA statement or type declaration statement in a block data program unit
(11.3), but objects in blank common shall not be initially defined."
The initialization of common blocks outside block-data program units is
supported by several compilers and thus one can consider allowing it for
-std=gnu.
program main
implicit none
integer, parameter:: nmin = 2
character(len=3) :: emname(nmin)=(/'bar','baz'/)
common/nmstr/emname
end program main
As NAG f95 kindly writes:
EMNAME has been initialised - can only be COMMON in BLOCK DATA
ifort -stand f95 diagnoses:
In Fortran 95, this DATA statement object cannot appear in either a blank
COMMON block or a named COMMON block.
but I like the mentioning of DATA BLOCK more.
Same, but with DATA:
program main
implicit none
integer, parameter:: nmin = 2
character(len=3) :: emname(nmin)
data emname/ 'bar','baz' /
common/nmstr/emname
end program main
And for blank commons:
program main
implicit none
integer, parameter:: nmin = 2
character(len=3) :: emname(nmin) = [ 'Aaa','aaa']
common//emname
end program main
gfortran (w/o patch):
Previously initialized symbol 'emname' in blank COMMON block at (1)
Similarly to above, gfortran misses the initialization with DATA. (With the
patch, neither diagnosed):
program main
implicit none
integer, parameter:: nmin = 2
character(len=3) :: emname(nmin)
data emname/ 'bar','baz' /
common//emname
end program main
Note: For blank commons, one should not point to BLOCK DATA as they are not
allowed there. gfortran (patched and unpatched) correctly diagnoses (default
options):
Warning: BLOCK DATA unit cannot contain blank COMMON
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|enhancement |normal
Keywords| |accepts-invalid
Summary|initialized symbol in |initialized symbol in
|common: Better error message|COMMON: Missing checks
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34227