Skip to content

Delete unenforced C7108 in favor of portable interpretation #348

@klausler

Description

@klausler

F'2023 C7108 prohibits the use of structure constructors that are ambiguous with generic function references:

"(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)."

No Fortran compiler to which I have access enforces this constraint. Instead, the common practice is to resolve the ambiguous call to a specific procedure of the generic function.

Example:

module m
  type foo
    integer n
  end type
  interface foo
    procedure bar0, bar1, bar2, bar3
  end interface
 contains
  type(foo) function bar0(n)
    integer, intent(in) :: n
    print *, 'bar0'
    bar0%n = n
  end
  type(foo) function bar1()
    print *, 'bar1'
    bar1%n = 1
  end
  type(foo) function bar2(a)
    real, intent(in) :: a
    print *, 'bar2'
    bar2%n = a
  end
  type(foo) function bar3(L)
    logical, intent(in) :: L
    print *, 'bar3'
    bar3%n = merge(4,5,L)
  end
end

program p
  use m
  type(foo) x
  x = foo(); print *, x       ! ok, not ambiguous
  x = foo(2); print *, x      ! ambigous
  x = foo(3.); print *, x     ! ambiguous due to data conversion
  x = foo(.true.); print *, x ! ok, not ambigous
end

Given that the resolution of the ambiguous call in favor of the function is portable, it might as well be standard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions