To: J3 J3/15-192r2 From: Steve Lionel & Dan Nagle Subject: STOP and ERROR STOP Enhancement Keywords: STOP, ERROR STOP Date: 2015 August 06 Reference: 15-007r1, N2059 Introduction ------------ Work item UK-23 relaxed restrictions on the stop code in STOP and ERROR STOP. The following text is copied from there: Basic Functionality: Add ability to execute STOP and ERROR STOP statements with a non-constant stop-code. Rationale: (a) There is no significant reason to require the stop-code in a STOP or ERROR STOP statement to be constant. (b) It is tedious when writing error checks to have to expand what would be a simple one-line logical IF into a 4-line IF construct that first prints a string that is variable (e.g. a dummy argument) and then executes a STOP or ERROR STOP statement. (c) It is not possible to return a variable process exit status from a Fortran program via STOP or ERROR STOP. This may be desirable, for example, when a program executed via EXECUTE_COMMAND_LINE fails, in which case one might wish to exit with the same exit status as the failed program. This functionality is frequently accessible by using the C "exit" function, but that is not guaranteed to be available. (d) In the case of error termination with ERROR STOP in a pure procedure, it is not possible to provide more information that might indicate what the problem is or whence it was called, as external file output is not allowed there. During discussion of UK-23 a further enhancement was proposed: The standard currently says that for the STOP and ERROR STOP statements that the stop code "is made available in a processor-dependent manner." A common implementation of this is to display a message on the standard error output unit such as "FORTRAN STOP 1234". Many users have requested the ability to suppress display of this message, especially as the standard also encourages implementations to return integer stop codes as the program's exit status. Users have also requested the ability to suppress the standard's required "warning" indicating which exceptions are currently signaling. Some implementations provide a mechanism, such as environment variables, to suppress display of these messages; standard syntax for this option is desirable. The sense of the committee was a preference for "all or nothing" control rather than a more fine-grained control, as long as the syntax could be extended in a future standard should further control be desired. Specification ------------- Permit non-constant stop codes in both STOP and ERROR STOP. Add syntax to the STOP and ERROR STOP statements to allow programmer execution-time control of the display of the stop code message and the exception warning. The constraint that the stop-code is to be of default kind remains. Syntax ------ Change the and productions to be: STOP [stop-code] [, QUIET = scalar-logical-expression] ERROR STOP [stop-code] [, QUIET = scalar-logical-expression] Change the productions to , and to . Edits ----- [xviii] Introduction Add to "Data usage and computation": The stop code in a STOP or ERROR STOP statement can be nonconstant. Output of the stop code and exception summary from STOP and ERROR STOP can now be controlled. [189:15-19] 8.4 STOP and ERROR STOP statements Replace the three syntax rules and the constraint with the following: R849 stop-stmt is STOP [ stop-code ] [, QUIET = scalar-logical-expr ] R850 error-stop-stmt is ERROR STOP [ stop-code ] [, QUIET = scalar-logical-expr ] R851 stop-code is scalar-default-char-expr or scalar-int-expr C848 (R851) The scalar-int-expr shall be of default kind. [189:23p2] 8.4 STOP and ERROR STOP statements Remove "also" [189:29-31p2] 8.4 STOP and ERROR STOP statements End the paragraph at line 28, deleting lines 29-31. Insert two new paragraphs, incorporating the text from lines 29-31, as follows: If QUIET is omitted or is specified to be false: - if any exception (14) is signaling on that image, the processor shall issue a warning indicating which exceptions are signaling; this warning shall be on the unit identified by the named constant ERROR_UNIT (13.9.2.8). - if a stop code is specified, it is recommended that the code be made available by formatted output to the same unit. If QUIET is specified to be true, no output of signaling exceptions or stop code shall be produced. (The editor is encouraged to reformat the above text should he find it stylistically appropriate.)