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

            Bug ID: 62296
           Summary: EXECUTE_COMMAND_LINE not F2008 conforming
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gmx dot de

It appears that EXECUTE_COMMAND_LINE does not fully conform to F2008
in case the execute command fails.

F2008, 13.7.57 states:

CMDSTAT (optional) shall be a default integer scalar. It is an INTENT (OUT)
argument. It is assigned the value −1 if the processor does not support
command line execution, a processor-dependent positive value if an error
condition occurs, or the value −2 if no error condition occurs but WAIT
is present with the value false and the processor does not support
asynchronous execution. Otherwise it is assigned the value 0.
[...]
If a condition occurs that would assign a nonzero value to CMDSTAT but the
CMDSTAT variable is not present, error termination is initiated.


However, the following example behaves as follows:

program gfcbug126
  integer :: stat, cstat
  call execute_command_line ("/bin/true",  exitstat=stat, cmdstat=cstat)
  print *, stat, cstat
  call execute_command_line ("/bin/false", exitstat=stat, cmdstat=cstat)
  print *, stat, cstat
  call execute_command_line ("/bin/true",  exitstat=stat)
  print *, stat
  call execute_command_line ("/bin/false", exitstat=stat)
  print *, stat
end

Output:
           0           0
           1           0
           0
           1

I think the correct output should be like:
           0           0
           1           (some positive number, e.g. 1)
           0
 (error termination)

e.g. xlf 14.1 produces:
 0 0
 1 1
 0
"gfcbug126.f90", line 9: 1525-610 Error encountered while attempting to execute
the command:
/bin/false

Also, the (online) documentation should be adjusted to match the standard.

Reply via email to