Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Bug(?) with elemental function and allocatable actual argument

Wolf_W_
New Contributor I
458 Views

Hello!

I am getting some odd results, when i try to use the allocatable return value of a function directly as an argument of another function. Is this behavior intendet, or is this usage of the elemental-keyword false? I use the 15.0.2 compiler.

program main
  implicit none

  character(4)              :: test_char = "Test"
  character(:), allocatable :: temp_alloc
  character(10)             :: temp_fixed

  ! This should be the result
  ! 'Test\foo'
  write(*,*) test_char // "\" // foo()

  ! This is the result
  ! 'foo f .'
  write(*,*) concat(test_char, foo())

  ! It works as intendet, when the result of 'foo' is stored in a variable
  temp_alloc = foo()
  write(*,*) concat(test_char, temp_alloc)
  temp_fixed = foo()
  write(*,*) concat(test_char, temp_fixed)

contains

  function foo()
    character(:), allocatable :: foo
    foo = "foo"
  end function foo

! There are no problems without the 'elemental'-keyword
  elemental function concat(var1,var2) result(var_result)
    character(*), intent(in) :: var1, var2
    character(len=max(len(var1),1)+len(var2)+1) :: var_result
!    character(8) :: var_result ! This does not work, too.

    var_result = var1 // "\" // var2

  end function concat

end program

 

0 Kudos
2 Replies
FortranFan
Honored Contributor III
458 Views

To me, this appears to be a bug in Intel Fortran.  I too fail to find anything in the Fortran standard that would preclude the use of elemental functions in such a context.  But you may want to consider posting this on comp,lang.fortran to see what a broad spectrum of folks (some with detailed knowledge of the standard) think of this.

0 Kudos
Steven_L_Intel1
Employee
458 Views

I think this is a known bug, but I will check when I get back to the office Thursday.

0 Kudos
Reply