Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28493 Discussions

Unexpected "error #6773: An equals sign (=) is invalid in this context" with use of structure constructor in a named constant

FortranFan
Honored Contributor II
731 Views

The following simple code gives unexpected "error #6773: An equals sign (=) is invalid in this context" with the use of structure constructor in a named constant, but the error doesn't occur in an assignment statement.

module m

   implicit none

   integer, parameter :: N = 1

   integer, parameter :: C(N) = [ 0 ]

   type :: t
      integer :: x(N)
   end type t

contains

   subroutine foo()

      type(t) :: t1
      type(t), parameter :: t2 = t( x = C )

      t1 = t( x = C )

      return

   end subroutine foo

end module m

I'm using the initial release of compiler 16 (v16.0.0.110):

Compiling with Intel(R) Visual Fortran Compiler 16.0 [Intel(R) 64]...
m.f90
m.f90(18): error #6773: An equals sign (=) is invalid in this context.   
compilation aborted for m.f90 (code 1)

I can't find anything in the standard suggesting anything invalid with the above shown structure constructor in a named constant as opposed to the assignment, but may be I'm missing something.  I appreciate feedback on this error.

0 Kudos
7 Replies
FortranFan
Honored Contributor II
731 Views

FWIW, the above code compiles with no errors in gfortran and a test executes as expected.

0 Kudos
Kevin_D_Intel
Employee
731 Views

Thank you FortranFan. I will investigate this.

0 Kudos
FortranFan
Honored Contributor II
731 Views

A blast from the past!  Here's some sidebar tidbit.

When I try a slight variant of the code in the original post, I get the following error in Compaq Visual Fortran:

--------------------Configuration: m - Win32 Debug--------------------
Compiling Fortran...
m.f90
m.f90(19) : Error: An equals sign (=) is invalid in this context.   
      t1 = t( x = C )
--------------^
Error executing df.exe.

m.obj - 1 error(s), 0 warning(s)

The code is:

module m

   implicit none

   integer, parameter :: N = 1

   integer, parameter :: C(N) = (/ 0 /)

   type :: t
      integer :: x(N)
   end type t

contains

   subroutine foo()

      type(t) :: t1

      t1 = t( x = C )

      return

   end subroutine foo

end module m

Now this particular code variant works in the current Intel compiler, but it's interesting how the text of the error from Compaq Visual Fortran is exactly the same as in the current compiler, illustrating its roots!  It makes sense that Compaq Visual Fortran would throw an error since structure constructor with named arguments was only introduced starting with the Fortran 2003 standard.  Is this a case where the compiler, when updated to support Fortran 2003, had things fixed up for processing of assignment statements but not for named constants?! :-)

 

0 Kudos
Kevin_D_Intel
Employee
731 Views

I reported this to Development and will let you know what I hear back.

(Internal tracking id:  DPD200376064)

0 Kudos
FortranFan
Honored Contributor II
731 Views

Kevin Davis (Intel) wrote:

I reported this to Development and will let you know what I hear back.

(Internal tracking id:  DPD200376064)

Ok, thanks.

0 Kudos
FortranFan
Honored Contributor II
731 Views

For whatever reason, the following variant of the code in the original post is accepted by the compiler:

module m

   implicit none

   integer, parameter :: N = 1

   integer, parameter :: C(N) = [ 0 ]

   type :: t
      integer :: x(N)
   end type t

contains

   subroutine foo()

      integer :: i
      type(t), parameter :: t1 = t( x = [ (C(i), i=1,N) ] )

      return

   end subroutine foo

end module m

 

0 Kudos
Kevin_D_Intel
Employee
731 Views

Interesting. Thanks for the info. I added this variant to the earlier internal tracking id noted.

0 Kudos
Reply