https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77506
Bug ID: 77506
Summary: stamdard for f2008 does not allow CHARACTER(LEN=*) in
array constructor
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: urbanjost at comcast dot net
Target Milestone: ---
I posted to fortran.comp.org a question on whether LEN=* was allowed in an
array
constructor. The concensus as that it is not standard, but gfortran 5.0.4
allows it without reporting it when -std=f2008 option is used. The dialog from
the newgroup (including two very short example programs) follows:
Can "CHARACTER(LEN=*)" be used in an array constructor?
The standard appears to state strings have to be the same length in an array
constructor
unless a length type parameter is specified (NOTE 4.74). And a type-spec
cannot contain
a deferred type parameter LEN=:. I thought that C418 also prohibited LEN=*,
but
gfortran 5.4.0 appears to allow LEN=* as a length type parameter. Is this an
extension
or standard? If standard, should the resulting length of the elements be
determined by
the longest value in the array constructor or by the length of the first
element or must
all values be the same length? This test program and it's output shows that in
this
particular programming environment (gfortran 5.4.0) that LEN=* is allowed and
that the
resulting array has elements trimmed to the length of the first element length
when the elements in the constructor are deferred length.
More specifically, can anyone clarify if the following is a standard program?
>
> character(len=:),allocatable :: textblock(:)
> ! constants of same length
> ! does LEN=* violate C418?
> textblock=[ character(len=*) :: 'abc ', '123456']
> write(*,'(a)')textblock
> end
>
> Output is:
> abc
> 123456
>
Or, is this standard?
> character(len=:),allocatable :: all1,all2
> ! deferred of different lengths in this case
> all1='ABC'
> all2='abcdefghij'
> textblock=[ character(len=*) :: all1, all2]
> write(*,'(a)')textblock
> end
>
Output is:
> abc
> ABC
References:
>
> NOTE 4.74
> An example of an array constructor that specifies a length type parameter:
>
> [ CHARACTER(LEN=7) :: 'Takata', 'Tanaka', 'Hayashi' ]
>
> In this constructor, without the type specification, it would have been
> necessary to specify all of the constants
> with the same character length.
>
> C418 (R420 R421 R422) A type-param-value of * shall be used only
> · to declare a dummy argument,
> · to declare a named constant,
> · in the type-spec of an ALLOCATE statement wherein each allocate-object
> is a dummy argument of type
> CHARACTER with an assumed character length,
> · in the type-spec or derived-type-spec of a type guard statement
> (8.1.9), or
> · in an external function, to declare the character length parameter of
> the function result.
!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Ian Harvey
Sep 6 (34 minutes ago)
That use of LEN=* is not standard conforming - as the constraint you
mention and quote below indicates.
I expect that the lack of diagnostic is just an oversight with that
compiler, rather than a deliberate extension.
(Another compiler I tried died with an ICE, so it is a common oversight!)
The normative requirement for the items in an array constructor to have
the same corresponding length parameters, in the absence of a leading
/type-spec/, is in F2008 4.8p2, as modified by TC2.
None of the programs are conforming, because of the above.