Skip to content

F_Front: unable to assign a ponter to a substring of a target string #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
skosukhin opened this issue Nov 6, 2020 · 1 comment
Open

Comments

@skosukhin
Copy link
Contributor

I assume that the following is legal Fortran:

MODULE A
CONTAINS
  SUBROUTINE foo()
    character(len=256), target :: t
    character(:), pointer :: p

    p => t(1:2)
  END SUBROUTINE foo
END MODULE A

However, F_Front fails to process it with the following error:

"a.f90", line 10: compiler error: outx_pointerAssignStatement: Invalid argument, expected F_VAR or ARRAY_REF or F95_MEMBER_REF of FUNCTION_CALL.
@skosukhin
Copy link
Contributor Author

I was thinking about a workaround but my knowledge of Fortran is not enough for this.
Say, we have the following:

PROGRAM A
  CHARACTER(LEN=256), TARGET :: t
  CHARACTER(:), POINTER :: p

  t = "123"
  p => t(1:2)
  PRINT *, '"', p, '"'

  t = "456"
  PRINT *, '"', p, '"'
END PROGRAM A

The program is expected to produce the following output:

 "12"
 "45"

but, as reported, F_Front fails to process the source file.

The workaround I thought about was to introduce a buffer variable as follows:

PROGRAM A
  CHARACTER(LEN=256), TARGET :: t
  CHARACTER(:), POINTER :: p
  CHARACTER(LEN=256), TARGET :: buf

  t = "123"
  buf = t(1:2)
  p => buf
  PRINT *, '"', p, '"'

  t = "456"
  PRINT *, '"', p, '"'
END PROGRAM A

F_Front is able to process this but the output of the program is not what we need (and it's obvious to me now why):

 "12                                                                                                                                                                                                                                                              "
 "12                                                                                                                                                                                                                                                              "

Maybe someone could help me to come up with a proper workaround for this for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant