Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Bug(?) with elemental function and allocatable actual argument

$
0
0

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

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>