[J3] [EXTERNAL] Elemental type-bound functions not useful

Van Snyder van.snyder at sbcglobal.net
Tue Mar 30 01:09:21 UTC 2021


On Mon, 2021-03-29 at 20:34 -0400, Vipul Parekh wrote:
> For the use case mentioned by Van here involving ELEMENTAL operations
> of the type 'A = B + C', I personally think the code design should
> have the objects 'A", ''B', 'C' as all nonpolymorphic - they can be
> ALLOCATABLE/POINTER - but they can all be of the same dynamic type
> that is an extension of an ABSTRACT derived type but which is itself
> inextensible.

The problem can arise independently of whether B and C are polymorphic.
If they're nonpolymorphic of a type that is an extension of the base
type, the function in the base type, that necessarily has at least one
polymorphic argument, will be invoked, and produce an object of the
base type. The assignment won't work if A is nonpolymorphic and of the
extension type. It will work if A is polymorphic and of the base type,
but (if it's allocatable) its dynamic type will be the base type, not
the declared type of A and B. This could be a nasty surprise.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210329/90593ce4/attachment.htm>


More information about the J3 mailing list