[J3] F2023:C7108 questions

Steven G. Kargl kargl at uw.edu
Sat Mar 23 21:11:09 UTC 2024


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3950 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240323/a171f67e/attachment.bin>


More information about the J3 mailing list