11module finalizable_m
2- ! ! This module supports the specification_expression_finalization main program
3- ! ! (at the bottom of this file), which in turn supports the check_specification_expression
4- ! ! unit-test function in ../test/compiler_test.f90.
2+ ! ! This module supports the main program at the bottom of this file, which
3+ ! ! tests compiler conformance with clause 7.5.6.3, paragraph 6 in the Fortran
4+ ! ! Interpretation Document (https://j3-fortran.org/doc/year/18/18-007r1.pdf):
5+ ! ! "If a specification expression in a scoping unit references
6+ ! ! a function, the result is finalized before execution of the executable
7+ ! ! constructs in the scoping unit." (The same statement appears in clause
8+ ! ! 4.5.5.2, paragraph 5 of the Fortran 2003 standard.) In such a scenario,
9+ ! ! the final subroutine must be pure. The only way to observe output from
10+ ! ! a pure final subroutine is for the subroutine to execute an error stop
11+ ! ! statement. A correct execution of this test will error-terminate and ouput
12+ ! ! the text "finalize: intentional error termination to verify finalization".
513 implicit none
614
715 private
@@ -29,14 +37,22 @@ pure function construct(component) result(finalizable)
2937 pure function component (self ) result(self_component)
3038 type (finalizable_t), intent (in ) :: self
3139 integer self_component
40+ #ifdef XLF
41+ if (.not. associated (self% component_)) error stop 1 ! work around xlf2003_r bug reported via OLCF (Ticket OLCFHELP-9069)
42+ #else
3243 if (.not. associated (self% component_)) error stop " component: unassociated component"
44+ #endif
3345 self_component = self% component_
3446 end function
3547
3648 pure subroutine finalize (self )
3749 type (finalizable_t), intent (inout ) :: self
3850 if (associated (self% component_)) deallocate (self% component_)
51+ #ifdef XLF
52+ error stop 2 ! work around xlf2003_r bug reported via OLCF (Ticket OLCFHELP-9069)
53+ #else
3954 error stop " finalize: intentional error termination to verify finalization"
55+ #endif
4056 end subroutine
4157
4258end module
@@ -52,6 +68,8 @@ program specification_expression_finalization
5268
5369 subroutine finalize_specification_expression_result
5470 real tmp(component(finalizable_t(component= 0 ))) ! ! Finalizes the finalizable_t function result
71+ real eliminate_unused_variable_warning
72+ tmp = eliminate_unused_variable_warning
5573 end subroutine
5674
5775end program
0 commit comments