Fortran 2018 RESULT statement followed by RETURN in internal functions: portable or unspecified?
0 reputation · 17 Aug 2024, 17:28 UTC
Background
I am reviewing a codebase that targets the Fortran 2018 standard and contains internal functions where a RESULT assignment is immediately followed by a RETURN statement. The standard defines how RESULT assigns the function value, but I cannot find wording that explicitly permits or forbids placing RETURN directly after it, which appears to leave the construct in unspecified territory.
Concern
My understanding is that mainstream compilers (gfortran, Intel Fortran, and similar) typically accept this pattern, but vendor documentation is inconsistent about whether the trailing RETURN is a no-op or undefined behavior. This matters because the code must compile and behave identically across several compiler versions and standard-compliance modes, and I want to avoid relying on an extension that could change in a future release.
Questions
- Does the Fortran 2018 standard actually leave a
RETURNimmediately afterRESULTunspecified, or is there normative wording I have missed that settles it? - Is there a documented portability risk (warnings, differing codegen, static-analysis issues) that justifies refactoring these functions now?
- What is the most reliable way to verify a given compiler's handling, short of inspecting generated assembly?