- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code (built with ifx 2025.2.1 on Windows) produces two compile-time errors that I believe are incorrect:
PROGRAM P
USE ISO_FORTRAN_ENV, ONLY : TEAM_TYPE
IMPLICIT NONE (TYPE, EXTERNAL)
TYPE(TEAM_TYPE) ODDEVEN
BLOCK
CHANGE TEAM (ODDEVEN)
END TEAM
EXIT
END BLOCK
B: BLOCK
CHANGE TEAM (ODDEVEN)
END TEAM
EXIT B
END BLOCK B
END PROGRAM P
The error messages are:
error #7974: If no construct name is specified, the EXIT statement must only be used inside a DO construct.
and
error #8940: A branch within a CHANGE TEAM construct must not have a branch target that is outside the construct. [LB]
Note that the last part of the second error message seems to randomly change from [LB] to [LA] depending on the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think error #7974 is correct the block construct must have a name to be able to use exit. That is true of all named constructs, the anomaly is do loops where no name is needed.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think error #7974 is correct the block construct must have a name to be able to use exit. That is true of all named constructs, the anomaly is do loops where no name is needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@andrew_4619 is correct, the exit is not allowed in this context. 2 other compilers agree:
nagfor:
nagfor -c exit_block.f90
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7231
Error: exit_block.f90, line 8: EXIT with no construct-name is not within any DO loop
detected at EXIT@<end-of-statement>
[NAG Fortran Compiler pass 1 error termination, 1 error]
and gfortran
gfortran exit_block.f90
exit_block.f90:9:8:
9 | EXIT
| 1
Error: EXIT statement at (1) is not within a construct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interesting. If we remove the obvious problem with the first exit, and leave this:
$ more exit_block2.f90
PROGRAM P
USE ISO_FORTRAN_ENV, ONLY : TEAM_TYPE
IMPLICIT NONE (TYPE, EXTERNAL)
TYPE(TEAM_TYPE) ODDEVEN
B: BLOCK
CHANGE TEAM (ODDEVEN)
END TEAM
EXIT B
END BLOCK B
END PROGRAM P
with this change, nagfor and gfortran will compile this code. ifx will not:
ifx -c -coarray exit_block2.f90
exit_block2.f90: error #8940: A branch within a CHANGE TEAM construct must not have a branch target that is outside the construct. [LA]
compilation aborted for exit_block2.f90 (code 1)
I am not entirely sure on the legality of 'EXIT B' in this context. I will have to consult the team's Standards reps to see if this is bug. My initial read on this is that it is legal code. but the BLOCK context does add a twist to this. Interesting ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@andrew_4619 good catch! Mea culpa, for the first error the block construct should have a name indeed. But as @Ron_Green noted, the second scenario is definitely a bug. The error message does not make any sense since the EXIT statement is outside the CHANGE TEAM construct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page