https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117798

--- Comment #10 from kargls at comcast dot net ---
(In reply to Thomas Koenig from comment #9)
> F2023 states
> 
> The following Fortran 2018 features might have a different interpretation
> under this document.
> 
> After an allocatable deferred length character variable is assigned a
> value by an IOMSG= or ERRMSG= clause, is the unit in an internal WRITE
> statement, or is an INTENT (OUT) argument in a reference to an intrinsic
> subroutine, that variable might be of shorter or longer length under this
> document than under Fortran 2018, since this document specifies intrinsic
> assignment semantics for these assignments.
> 
> That is big... and will require quite some work (and thinking before)
> on how to handle that.

Fortunately, there are too many intrinsic subroutine.

  F23 16.2.1, p. 376

  Intrinsic subroutines that assign values to arguments of
  type character do so in accordance with the rules of
  intrinsic assignment (10.2.1.3).

  F23, 16.9.1, p. 387

  When an allocatable deferred-length character scalar corresponding
  to an INTENT(INOUT) or INTENT(OUT) argument is assigned a value,
  the value is assigned as if by intrinsic assignment.

Here's the list of intrinsic subroutines that are effected by the change.

16.9.57 CO_REDUCE(A, OPERATION [, RESULT_IMAGE, STAT, ERRMSG])
16.9.58 CO_SUM(A [, RESULT_IMAGE, STAT, ERRMSG])
16.9.69 DATE_AND_TIME([DATE, TIME, ZONE, VALUES])
16.9.83 EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG])
16.9.92 GET_COMMAND([COMMAND, LENGTH, STATUS, ERRMSG])
16.9.93 GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS, ERRMSG])
16.9.94 GET_ENVIRONMENT_VARIABLE(NAME [, VALUE, LENGTH, STATUS, TRIM_NAME,
                                 ERRMSG])
16.9.147 MOVE_ALLOC (FROM, TO [, STAT, ERRMSG])


Consider, get_command(),

   COMMAND (optional) shall be a default character scalar.  It is an
      INTENT(OUT) argument.  It is assigned the entire command by which
      the program was invoked.  If the command cannot be determined,
      COMMAND is assigned all blanks.

   ERRMSG (optional) shall be a default character scalar.  It is
      an INTENT (INOUT) argument.  It is assigned a processor-dependent
      explanatory message if the command retrieval fails.  Otherwise,
      it is unchanged.

J3 did not entirely loose their mind.  The last sentence is important.
It is as-if intrinsic assignment never occurs.  So, in principle one
can do

   character(len=:), allocatable :: cmd, msg
   msg = 'good'
   call get_command(cmd, msg)
   if (msg == 'good') then
      do something with cmd
   else
      print *, 'Error occurred.'
      print *, msg  
   end if

Note, it is unclear what cmd is if the command cannot be determined.

Reply via email to