[J3] F2023:C7108 questions

Malcolm Cohen malcolm at nag-j.co.jp
Sun Mar 24 00:27:09 UTC 2024


Hi Steve,

This is what we call a disambiguating constraint. It makes no requirement on
the user program. Its only effect is that when something could be
interpreted as a structure constructor or a generic procedure reference, the
generic procedure reference takes precedence.

And that resolution is determined by the type, kind, rank, and procedureness
of the arguments.

Cheers,
-- 
..............Malcolm Cohen, NAG Oxford/Tokyo.

-----Original Message-----
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Steven G. Kargl
via J3
Sent: Sunday, March 24, 2024 6:11 AM
To: J3 Fortran <j3 at mailman.j3-fortran.org>
Cc: Steven G. Kargl <kargl at uw.edu>
Subject: [J3] F2023:C7108 questions

All,

I am seeking clarification on the intent of F2023:C7108.
This constraint can be traced to F2003:C489.  Consider the
following code:

   !
   ! Fortran 2023:C7108 (R756) If derived-type-spec is a type name
   ! that is the same as a generic name, the component-spec-list
   ! shall not be a valid actual-arg-spec-list for a function
   ! reference that is resolvable as a generic reference to that
   ! name (15.5.5.2).
   !
   module foo
      implicit none
      type :: params
         real :: x
         real :: y
      end type params
      interface params
         module procedure default_params
      end interface
      contains
         function default_params(x, y) result(this)
            real, intent(in) :: x, y
            type(params) :: this
            this%x = x * 2 
            this%y = y * 2
         end function
   end module

   program chk_type_define
      use foo
      implicit none
      type(params) :: p
      !
      ! Is this a structure constructor or generic function reference?
      !
      p = params(3.0, 2.0)
      if (p%x /= 3 .or. p%y /= 2) stop 1
   end program chk_type_define

It seems to me that the constraint is to ensure that no ambiguity
occurs with the assignment in 'p = params(3.0, 2.0)'.  Is this 
correct?  If so, if the names of the components or dummy arguments
are changed, do the use of keywords remove the ambiguity?  That is,
'p = params(a = 3.0, 2.)' would be a reference to the generic function
if the first dummy argument of 'default_params' is 'a'.
  
-- 
Steve




More information about the J3 mailing list