1
1
module 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".
5
13
implicit none
6
14
7
15
private
@@ -29,14 +37,22 @@ pure function construct(component) result(finalizable)
29
37
pure function component (self ) result(self_component)
30
38
type (finalizable_t), intent (in ) :: self
31
39
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
32
43
if (.not. associated (self% component_)) error stop " component: unassociated component"
44
+ #endif
33
45
self_component = self% component_
34
46
end function
35
47
36
48
pure subroutine finalize (self )
37
49
type (finalizable_t), intent (inout ) :: self
38
50
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
39
54
error stop " finalize: intentional error termination to verify finalization"
55
+ #endif
40
56
end subroutine
41
57
42
58
end module
@@ -52,6 +68,8 @@ program specification_expression_finalization
52
68
53
69
subroutine finalize_specification_expression_result
54
70
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
55
73
end subroutine
56
74
57
75
end program
0 commit comments