Skip to content

Issues with Clause 7 #166

@everythingfunctional

Description

@everythingfunctional
  • 7.1.2 Type classification

Should we add some language here about "a type may be deferred"?

  • 7.1.4 Constants

Shoud we add some language here about how "the value of a named constant may be deferred"?

  • 7.3.2.2 TYPE type specifier

Add deferred-type to list in first sentence of second paragraph.

  • 7.3.2.3 CLASS type specifier

Add "or deferred-type" after "derived-type-spec" in the first sentence of the second paragraph

  • 7.5.6 Final subroutines

I think we have a hole here we need to patch related to procedure purity and final subroutines.
For example, we haven't done anything to prevent this violation.

template example(T)
    deferred type :: T
contains
    simple subroutine s()
        type(T) :: x
        ! local variable x gets finalized at end of subroutine
    end subroutine
end template
...
type :: my_t
contains
    final :: finalize_my_t
end type
...
subroutine finalize_my_t(x)
    type(my_t), intent(inout) :: x
    print *, "Hello there!"
end subroutine
...
instantiate example(my_t)
call s ! calling this simple subroutine will cause a print statement to be executed 😱 

Luckily, I think we have the tools to handle this now, with the passage of 25-153r1.
We should add PURE and SIMPLE as possible attributes to the deferred type declaration.
We'll need to say that intrinsic types, enum types, enumeration types,
or derived types that satisfy the constraints even if not declared with the PURE or SIMPLE attributes,
can be instantiation associated with deferred types that are PURE (or SIMPLE).
Then we say that something along the lines of
"A local variable of deferred type shall not be declared in a PURE or SIMPLE templated
procedure or in a PURE or SIMPLE procedure defined in a template unless the deferred type
has the PURE or SIMPLE attribute respectively."
As well as
"An entity of deferred type or of a derived type with a deferred type component
shall not appear as the variable in an intrinsic assignment statement,
nor be deallocated within a PURE or SIMPLE procedure unless that deferred type
has the PURE or SIMPLE attribute respectively."

I don't think we need to worry about any other cases, since they are generally handled
by the requirement for explicit interfaces and the existing rules about PURE and SIMPLE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions