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

Unexpected error when changing "len(STRING)" to "STRING%len"

ur
New Contributor II
1,485 Views

 

 

 

program testit
write(*,'(*(g0))')'[',atleast('',10),']'
write(*,'(*(g0))')'[',atleast('a',10),']'
write(*,'(*(g0))')'[',atleast('ab',10),']'
write(*,'(*(g0))')'[',atleast('abc',10),']'
write(*,'(*(g0))')'[',atleast('abcdefghijklmopqrstuvwxyz',10),']'
write(*,'(*(g0))')'[',atleast('',10,'_'),']'
write(*,'(*(g0))')'[',atleast('a',10,'_'),']'
write(*,'(*(g0))')'[',atleast('ab',10,'_'),']'
write(*,'(*(g0))')'[',atleast('abc',10,'_'),']'
write(*,'(*(g0))')'[',atleast('abcdefghijklmopqrstuvwxyz',10,'_'),']'
contains
function atleast(line,length,pattern) result(strout)
!$@(#) M_strings::atleast(3f): return string padded to at least specified length
character(len=*),intent(in) :: line
integer,intent(in) :: length
character(len=*),intent(in),optional :: pattern
character(len=max(length,len(trim(line)))) :: strout
if(present(pattern))then
!!strout=line//repeat(pattern,strout%len/pattern%len+1)
strout=line//repeat(pattern,len(strout)/len(pattern)+1)
else
strout=line
endif
end function atleast
end program testit
!bug1.f90(20): error #6460: This is not a component name that is defined in the encompassing structure. [LEN]
! strout=line//repeat(pattern,strout%len/pattern%len+1)
! --------------------------------------^
! bug1.f90(20): error #6158: The structure-name is invalid or is missing. [STROUT]
! strout=line//repeat(pattern,strout%len/pattern%len+1)
! -------------------------------^

 

 

 

A little procedure has worked for a long time with at least three compilers. If At line 20 I change "len(pattern)" to "pattern%len"  it is fine, but if I change "len(strout)" to "strout%len" I get the errors show from line 27 to 32.   It seems to me that line 20 is the equivalent of line 21 and should work.

Should line 20 work, or produce an error?

0 Kudos
1 Solution
Igor_V_Intel
Employee
1,372 Views

The problem is escalated to the Intel Fortran compiler development team. Thank you for reporting it.


View solution in original post

4 Replies
andrew_4619
Honored Contributor III
1,441 Views

I haven't studied your issue but an observation len(trim(line)) would seems unnecessary why not use len_trim(line) or indeed just make the return string allocatable and make use of allocate LHS.

ur
New Contributor II
1,431 Views

Could do it several ways; but the question for me is really why I get an error message when replacing len(string) with string%len for the returned value, but it works with other compilers.  I think it is a compiler bug but not quite sure it might be non-standard usage

0 Kudos
FortranFan
Honored Contributor III
1,415 Views

It's a compiler bug, Intel team can start with this simple example:

contains
   function f( n ) result(r)
      character(len=n) :: r 
      r = ""
      print *, r%len
   end function
end 
C:\temp>ifx /c /standard-semantics p.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.0.0 Build 20221201
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

p.f90(18): error #6460: This is not a component name that is defined in the encompassing structure.   [LEN]
      print *, r%len
-----------------^
p.f90(18): error #6158: The structure-name is invalid or is missing.   [R]
      print *, r%len
---------------^
compilation aborted for p.f90 (code 1)
Igor_V_Intel
Employee
1,373 Views

The problem is escalated to the Intel Fortran compiler development team. Thank you for reporting it.


Reply