2 ! { dg-options "-fdump-tree-original" }
4 ! Test conformance with clause 7.5.6.3, paragraph 6 of F2018. Part of PR106576.
6 ! Contributed by Damian Rouson <damian@archaeologic.codes>
9 !! This module supports the main program at the bottom of this file, which
10 !! tests compiler conformance with clause 7.5.6.3, paragraph 6 in the Fortran
11 !! Interpretation Document (https://j3-fortran.org/doc/year/18/18-007r1.pdf):
12 !! "If a specification expression in a scoping unit references
13 !! a function, the result is finalized before execution of the executable
14 !! constructs in the scoping unit."
18 public :: finalizable_t, component
22 integer, allocatable :: component_
27 interface finalizable_t
28 module procedure construct
33 pure function construct(component) result(finalizable)
34 integer, intent(in) :: component
35 type(finalizable_t) finalizable
36 allocate(finalizable%component_, source = component)
39 pure function component(self) result(self_component)
40 type(finalizable_t), intent(in) :: self
41 integer self_component
42 self_component = self%component_
45 pure subroutine finalize(self)
46 type(finalizable_t), intent(inout) :: self
47 if (allocated(self%component_)) deallocate(self%component_)
52 program specification_expression_finalization
53 use finalizable_m, only : finalizable_t, component
56 call finalize_specification_expression_result
60 subroutine finalize_specification_expression_result
61 real tmp(component(finalizable_t(component=1))) !! Finalizes the finalizable_t function result
62 real eliminate_unused_variable_warning
63 tmp = eliminate_unused_variable_warning
67 ! { dg-final { scan-tree-dump-times "_final != 0B" 1 "original" } }