Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28455 Discussions

Procedure pointer not assumed to be pure

Weiss__Christian
899 Views

This code snippet does not compile with ifort version >= 19 (but does e.g. with gfortran 10):

 

module test
  type test_t
    procedure(), pointer, nopass :: do_something => null()
  end type test_t

  type(test_t) :: this_test

contains

  pure subroutine check ()
    call this_test%do_something()
  end subroutine check
end module test

 

With error message "Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE. [DO_SOMETHING]"

 

This error can be avoided by defining an explicit interface:

 

  interface 
    pure subroutine foo()
    end subroutine foo
  end interface

  type test_t
    procedure(foo), pointer, nopass :: do_something => null()
  end type test_t

 

I found out that in version 19, the treatment of procedures as pure has been changed (https://software.intel.com/content/www/us/en/develop/articles/intel-fortran-compiler-191-for-linux-release-notes-for-intel-parallel-studio-xe-2020.html#changed_comp_behaviour), but this deals with intrinsic procedures, especially c_f_procpointer.

 

At first glance, this looks as though the implicit interface assumed for "()" has no pure implementation. I would like to know if this behavior is intended. I could not find any further specifications in the Fortran standard, but maybe I did miss something?

0 Kudos
3 Replies
FortranFan
Honored Contributor II
886 Views

@Weiss__Christian ,

Based on my understanding, gfortran does not conform to the Fortran standard with the case you have posted.  Note the standard requires a PURE procedure to have an explicit interface.  And the standard does not permit a reference to an IMPURE subroutine in a pure procedure.

Steve_Lionel
Honored Contributor III
884 Views

The standard is quite clear here:

"C1595 Any procedure referenced in a pure subprogram, including one referenced via a defined operation, defined assignment, defined input/output, or finalization, shall be pure.

The form of a procedure reference is dependent on the interface of the procedure or procedure pointer, but is independent of the means by which the procedure is defined. (15.5.1p1)"

It does not matter whether the reference is to a procedure name or procedure pointer - if the reference is in a pure procedure, there must be an explicit interface that defines it as pure.

In my opinion, gfortran is in error by not diagnosing this.

 

Weiss__Christian
848 Views

Thank you for these answers. 

0 Kudos
Reply