Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why C1529?

163 views
Skip to first unread message

Peter Klausler US

unread,
Dec 12, 2022, 5:37:33 PM12/12/22
to
Constraint C1529 reads "If data-ref is an array, the referenced type-bound procedure shall have the PASS attribute."

So this is not conformant:
> type dt
>. contains
> procedure, nopass :: tbp => mysubr
> end type
> ...
> subroutine mysubr
> end
> ...
> type(dt) x(2)
> call x%tbp

because 'x' is not scalar, even though the value of 'x' has nothing to do with the semantics of the call.

I'm wondering why this constraint exists, and whether to enforce it with a hard error message. Only two compilers do so; at least three don't care. There's nothing ambiguous about the resolution of the type-bound procedure when the base object is not scalar, so it seems best to accept it in the interest of making codes easier to port. But maybe I'm missing something subtle that makes strict enforcement of constraint C1529 necessary to avoid some otherwise bad or unimplementable behavior.

FortranFan

unread,
Dec 13, 2022, 7:32:41 PM12/13/22
to
On Monday, December 12, 2022 at 5:37:33 PM UTC-5, Peter Klausler US wrote:

> .. There's nothing ambiguous about the resolution of the type-bound procedure when the base object is not scalar ..

The type-bound procedure "mysubr" is shown to have no arguments but the reference has a default integer literal constant as the argument, so how will that work?

Separately, say the type-bound procedure is declared like so:
subroutine mysubr( x )
integer, intent(inout) :: x
x = x + 1
end subroutine

and the caller has the following:
..
integer :: n(3)
type(dt) foo(2)
n = [ 1, 2, 3 ]
call foo%tbp( n )
..

Then how does the processor complete the resolution of the type-bound procedure unambiguously with the shape mismatch in the derived type "foo" and the actual argument "n"? The standard provides no interpretation for this since it seeks to disallow this scenario with C1529.

Peter Klausler US

unread,
Dec 13, 2022, 8:03:52 PM12/13/22
to
On Tuesday, December 13, 2022 at 4:32:41 PM UTC-8, FortranFan wrote:
> On Monday, December 12, 2022 at 5:37:33 PM UTC-5, Peter Klausler US wrote:
>
> > .. There's nothing ambiguous about the resolution of the type-bound procedure when the base object is not scalar ..
>
> The type-bound procedure "mysubr" is shown to have no arguments but the reference has a default integer literal constant as the argument, so how will that work?

No, the call does not have any actual arguments; it's just "call x%tbp".

Your modified test is not relevant.

rbader

unread,
Dec 14, 2022, 8:22:16 AM12/14/22
to
Since we're talking about the constraint, indeed the compiler is obliged to reject a violation. Note that C1529 implies that the dummy object must be a scalar (see C760), so the only way to enable using an array as an actual argument is to declare the procedure elemental.

If the constraint were not present in the language, surely some additional words would be needed to uniquely clarify what exactly should be done when invoking the procedure through the array object (witness the elemental vs non-elemental case). I suspect this was suppressed since the complications exceed any value (you can, after all, say "call x(1)%tbp" if you want), and also to make the TBP semantics as uniform as possible across the board (minimize cognitive load).

Cheers
Reinhold

Peter Klausler US

unread,
Dec 14, 2022, 10:15:27 AM12/14/22
to
On Wednesday, December 14, 2022 at 5:22:16 AM UTC-8, rbader wrote:
> Note that C1529 implies that the dummy object must be a scalar (see C760), so the only way to enable using an array as an actual argument is to declare the procedure elemental.

There is no dummy or actual argument here.

rbader

unread,
Dec 14, 2022, 1:39:22 PM12/14/22
to
Your example does not specify one, but then your example violates the constraint. If the constraint is obeyed, at least one dummy argument must exist.

Cheers
Reinhold

Peter Klausler US

unread,
Dec 14, 2022, 1:48:08 PM12/14/22
to
On Wednesday, December 14, 2022 at 10:39:22 AM UTC-8, rbader wrote:
> Your example does not specify one, but then your example violates the constraint. If the constraint is obeyed, at least one dummy argument must exist.

Thank you for your help.

Ron Shepard

unread,
Dec 15, 2022, 2:57:05 AM12/15/22
to
Can someone give a practical example of a situation where a type bound
procedure would not have an argument, or where, if it did have an
argument (e.g. due to language requirements), it might want to ignore it?

$.02 -Ron Shepard

rbader

unread,
Dec 15, 2022, 8:31:35 AM12/15/22
to
If the action of the procedure does not need any information from the object, but does depend on the type of the object.
Note that overriding of a TBP should work independently of whether the object is passed or not.

Simplest example would be a diagnostic printout "I am of type <whatever>".

Cheers
Reinhold

gah4

unread,
Dec 15, 2022, 1:58:11 PM12/15/22
to
On Thursday, December 15, 2022 at 5:31:35 AM UTC-8, rbader wrote:

(snip)

> If the action of the procedure does not need any information from the object,
> but does depend on the type of the object.

For Java, static methods don't depend on any object, and are normally
qualified with the name of the class. There are Math.sqrt() and Math.sin().

> Note that overriding of a TBP should work independently of whether the object is passed or not.

You can call a static method qualifying it with an object from the class.
It is resolved based on the declared class, not on an actual class of any object
that might, or might not be, assigned to it.

They are resolved at compile time, not at run time like object methods.

There should be a corresponding system in OO Fortran, though I
don't know how to do it.

Thomas Koenig

unread,
Dec 16, 2022, 1:11:45 AM12/16/22
to
Ron Shepard <nos...@nowhere.org> schrieb:
Could be initialization of some global structure, or writing out a
version number to standard output, or whatever :-)
0 new messages