Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

data statement with nested type constructors or compiler bug

6 views
Skip to first unread message

amgarching

unread,
Oct 22, 2009, 6:36:53 PM10/22/09
to
Dear All,

After upgrade to gcc 4.4.1 (Ubuntu Karmic) I get this kind of error
with
Gfortran for a data statment using type constructors:

w.f90:53.20:

data(dft_water_nuc(i), i=1,n_nuc) /
&
1
Error: non-constant array in DATA statement (1)

Is the code I attach below legal? If the code is legal then this might
be
a bug in Gfortran.

I can replace "data" with array constructor "[]" or remove
the conflicting entry to make it compile.

BTW what is the difference between "(/ /)" and "[]".

Alexei

=============== w.f90 =================
module w

implicit none
save
private

real, parameter :: zero = 0.0

type, public :: charge
real :: q
real :: C
real :: A
end type charge

type, public :: multpol
character*12 :: name
real :: coor(3) !!! COMMENT THIS TO MAKE IT COMPILE !!!
real :: mass
type(charge) :: z
end type multpol


integer, public, parameter :: n_nuc=3

type(multpol), public :: dft_water_nuc(n_nuc)

real, parameter :: C_i =zero
real, parameter :: A_i =zero

!names of multipole
character*12, parameter :: mname1="O1 "
character*12, parameter :: mname2="H2 "
character*12, parameter :: mname3="H3 "

!coordinates of multipole centers
real, parameter :: mcoor1(3)=(/ zero, zero, -0.119151/)
real, parameter :: mcoor2(3)=(/-1.431042, zero, 0.945510/)
real, parameter :: mcoor3(3)=(/ 1.431042, zero, 0.945510/)

!mass
real, parameter :: mass1=15.99491
real, parameter :: mass2=1.007825
real, parameter :: mass3=1.007825

!charges
real, parameter :: Zn1=8.0
real, parameter :: Zn2=1.0
real, parameter :: Zn3=1.0

integer :: i

!----------------------------------------------------------------
data(dft_water_nuc(i), i=1,n_nuc) /
&
multpol
( &
mname1, &
mcoor1, & !!! COMMENT THIS TO
MAKE IT COMPILE !!!
mass1, &
charge(Zn1,C_i,A_i)
&
),
&
multpol
( &
mname2, &
mcoor2, & !!! COMMENT THIS TO
MAKE IT COMPILE !!!
mass2, &
charge(Zn2,C_i,A_i)
&
),
&
multpol
( &
mname3, &
mcoor3, & !!! COMMENT THIS TO
MAKE IT COMPILE !!!
mass3, &
charge(Zn3,C_i,A_i)
&
)
&
/

end module w

Richard Maine

unread,
Oct 22, 2009, 8:21:08 PM10/22/09
to
amgarching <alexei....@gmail.com> wrote:

> Is the code I attach below legal? If the code is legal then this might
> be a bug in Gfortran.

[code elided]

Looks ok to me. NAG f95 agrees. G95 gets an internal compiler error.
Andy here?

One slight caveat. The continuations and line breaks are all messed up,
at least as it shows in my newsreader. I'm assuming that this is just an
artifact of the news posting/reading, but it is at least possible that a
bad continuation could generate a misleading error like this. Check that
al the "&" characters are at the end of the line to be continued - not
at the beginning of the next one (yes, I know it is also ok to have one
at the beginning of the next line, but if so that is an additional one;
you still need the one on the end of the prior line). ALso check that
you don't have line breaks between the "multpol" and "(" as I'm seeing.

> BTW what is the difference between "(/ /)" and "[]".

Absolutely nothing in terms of meaning. When array constructors were
introduced in f90, the "[" and "]" characters were not in the Fortran
character set and there was some reluctance to add them. The ugly (in my
opinion) "(/ /)" thing was done as a substitute. The "[]" was not
standardized until f2003, so it is at least possible that an f95
compiler might not support it. But that's pretty trivial as f2003
features go; I suspect most compilers support it by now unless you are
using an old version.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

Paul Thomas

unread,
Oct 23, 2009, 4:16:28 AM10/23/09
to
Alexei,

> Looks ok to me. NAG f95 agrees. G95 gets an internal compiler error.
> Andy here?

Indeed - it also worked for gfortran 4.4.0.

Could you file a bug report, please? Also, it needs to be marked in
the title line as a regression.

Thanks

Paul

Erik Toussaint

unread,
Oct 23, 2009, 6:58:11 AM10/23/09
to

It works for me with gfortran 4.5.0.
(To be exact: GNU Fortran (GCC) 4.5.0 20090421 (experimental) [trunk
revision 146519].)

Erik.

Paul Thomas

unread,
Oct 23, 2009, 8:20:25 AM10/23/09
to
Oh dear, oh dear,

> It works for me with gfortran 4.5.0.
> (To be exact: GNU Fortran (GCC) 4.5.0 20090421 (experimental) [trunk
> revision 146519].)

It fails for me with 4.5.0 20091019 - I guess that something,
somewhere is not being initialized.

I'll do the honours with the bug report.

Thanks

Paul

Paul Thomas

unread,
Oct 23, 2009, 8:28:16 AM10/23/09
to

> I'll do the honours with the bug report.

This is now Bug report 41807 in Bugzilla.

Thanks for the report

Paul

robin

unread,
Oct 23, 2009, 9:55:44 AM10/23/09
to
"amgarching" <alexei....@gmail.com> wrote in message
news:403c87c8-a823-49c1...@d4g2000vbm.googlegroups.com...

| Dear All,
|
| After upgrade to gcc 4.4.1 (Ubuntu Karmic) I get this kind of error
| with
| Gfortran for a data statment using type constructors:
|
| w.f90:53.20:
|
| data(dft_water_nuc(i), i=1,n_nuc) /
| &
| 1
| Error: non-constant array in DATA statement (1)

Try using:

data dft_water_nuc(1:n_nuc) / etc

| Is the code I attach below legal? If the code is legal then this might
| be
| a bug in Gfortran.
|
| I can replace "data" with array constructor "[]" or remove
| the conflicting entry to make it compile.
|
| BTW what is the difference between "(/ /)" and "[]".

Nothng.


0 new messages