(j3.2006) Unlimited poly and pointer component

Daniel C Chen cdchen
Wed Dec 20 10:40:08 EST 2017


Hello all,

I think the questions I asked is too vague to answer. Let me try it
again :).

This is a code fragment coming from one of our customers. They are calling
ASSOCIATED(this%p) where "this" is an polymorphic dummy argument with
declared type 't1' that corresponds to an unlimited polymorphic actual
argument. Since we don't do default initialization on "CLASS(t1), INTENT
(INOUT) :: this", it segfaults when "this%p" is referenced.

So the 1st question I had was if "this" is actually defined? Bring back the
further reduced code as:



program main
Type t1
integer, pointer :: p => NULL()
end type

Type(t1) :: d1
end program



The standard says
[527:20]: "A derived-type scalar object is defined if and only if all of
its nonpointer components are defined."
[529:28]: "(22) When a pointer becomes associated with a target that is
defined, the pointer becomes defined."
[528:2]: "Variables that are not initially defined are initially
undefined."

If a derived type only has pointer components, is an object of that type
considered initially defined or undefined?
I intend to say it is initially defined, but want to make sure that is the
correct interpretation.

I will probably ask the 2nd question after I clarify the 1st one..

Thanks very much for your input!

Daniel

XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran



From:	"Daniel C Chen" <cdchen at ca.ibm.com>
To:	"fortran standards email list for J3"
            <j3 at mailman.j3-fortran.org>
Date:	12/18/2017 04:42 PM
Subject:	(j3.2006) Unlimited poly and pointer component
Sent by:	"J3" <j3-bounces at mailman.j3-fortran.org>





Hello,

Case 1:

program main
Type dt
integer, pointer :: p => NULL()
end type

Type(dt) :: d1
end program

The standard says
[527:20]: "A derived-type scalar object is defined if and only if all of
its nonpointer components are defined."
[529:28]: "(22) When a pointer becomes associated with a target that is
defined, the pointer becomes defined."
[528:2]: "Variables that are not initially defined are initially
undefined."

Question: Is d1 initially undefined?

Case 2:

module m
type t1
integer, pointer :: p => NULL()
contains
procedure, private :: t1Assign
generic, public :: assignment(=) => t1Assign
end type t1

type t2
type(t1) :: base
end type t2

contains
subroutine t1Assign(this, src)
implicit none
class(t1), intent(inout) :: this !!! what if intent(out)
class(t1), intent(in) :: src
print *, associated(this%p) !!! AAA
end subroutine

subroutine copy(dest, src)
class(*), pointer :: dest
class(*), intent(in) :: src
allocate(dest, source=src)
end subroutine copy
end module

program main

use m
class(*), pointer :: aa
type(t2) :: bb

allocate(bb%base%p)
call copy(aa, bb)

end

Question 1: Is "this" at line AAA defined?

Question 2: if the answer of 1 is YES, then what should it print?
It seems this%p is not nullified because the default initialization doesn't
apply to unlimited polymorphic object (dest) nor to the intent(inout)
(this). Doesn't it mean the call to associated is invalid?

Question 3: if the answer to 1 is YES, if I change "this" in "t1Assign" to
"INTENT(OUT)"(so the default initialization is applied to "this"), is the
call to associated then legal, and it should print false?

Thanks

Daniel

XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.j3-2Dfortran.org_mailman_listinfo_j3&d=DwICAg&c=jf_iaSHvJObTbx-siA1ZOg&r=57cafTO2T1scnwZfrlLPsghkmjFH2AuUtlcWE5nRktg&m=tQpMpjI7UUwPgYcjm5VxYpDenBvh5qUNhLWcCv_YfMw&s=roKyXiSa9N5ifO-bi1o-r9rNwczQpQKcXA3nrk7Me94&e=



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171220/b2bb2cdd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20171220/b2bb2cdd/attachment.gif>



More information about the J3 mailing list