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

Is this code standard conforming?

91 views
Skip to first unread message

sfilippone

unread,
Feb 11, 2021, 10:10:45 AM2/11/21
to
It is my understanding that a GENERIC type-bound procedure set defined in a base type can be extended in an extended type, as the attached code does.

The code below has been extracted from a library, and it is the minimum size I have been able to reduce to whilst preserving the compiler behaviour; it compiles cleanly with GNU fortran but fails with Intel.

Any comments? Thanks a lot

Salvatore

----------- Intel -------------
[@login1: test]$ ifort -v
ifort version 19.1.1.217
[@login1: test]$ ifort -o tr tr.f90
tr.f90: error #5286: Ambiguous generic interface SET: previously declared specific procedure S_P_TYPE::M_SCPRECSETI is not distinguishable from this declaration. [B_S_P_TYPE::SCPRECSETI]
tr.f90(210): error #8486: There is no matching specific subroutine for this type bound generic subroutine call. [SET]
call sprec%set('Bar',1.0,info)
-------------^
tr.f90(211): error #8486: There is no matching specific subroutine for this type bound generic subroutine call. [SET]
call sprec%set(s_ag,info)
-------------^
compilation aborted for tr.f90 (code 1)

--------- GNU -----------
[@lagrange BugIntel]$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20201125 (Red Hat 10.2.1-9) (GCC)
[@lagrange BugIntel]$ gfortran -o tr tr.f90

-----------------------------------------------------------------
-----Source code tr.f90 -------------
module b_s_p_type

type bsp_type

contains
procedure, pass(prec) :: cseti => scprecseti
procedure, pass(prec) :: csetr => scprecsetr
generic, public :: set => cseti, csetr
end type bsp_type


interface
subroutine scprecseti(prec,what,val,info)
import :: bsp_type
class(bsp_type), intent(inout) :: prec
character(len=*), intent(in) :: what
integer, intent(in) :: val
integer, intent(out) :: info
end subroutine scprecseti
subroutine scprecsetr(prec,what,val,info)
import :: bsp_type
class(bsp_type), intent(inout) :: prec
character(len=*), intent(in) :: what
real, intent(in) :: val
integer, intent(out) :: info
end subroutine scprecsetr

end interface


end module b_s_p_type
subroutine scprecseti(p,what,val,info)

use b_s_p_type, protect_name => scprecseti

implicit none

! Arguments
class(bsp_type), intent(inout) :: p
character(len=*), intent(in) :: what
integer, intent(in) :: val
integer, intent(out) :: info


info = 0


end subroutine scprecseti

subroutine scprecsetr(p,what,val,info)
use b_s_p_type, protect_name => scprecsetr

implicit none
class(bsp_type), intent(inout) :: p
character(len=*), intent(in) :: what
real, intent(in) :: val
integer, intent(out) :: info

info = 0

end subroutine scprecsetr


module base_p_type

type ml_parms

end type ml_parms


type, extends(ml_parms) :: sml_parms

end type sml_parms


type saggr_data

end type saggr_data

end module base_p_type

module sba_mod

use base_p_type, only : sml_parms, saggr_data

type sba_type
end type sba_type

end module sba_mod

module sbs_mod

use base_p_type

type sbs_type

end type sbs_type

end module sbs_mod



module s_p_type

use base_p_type
use sbs_mod
use sba_mod
use b_s_p_type

type, extends(bsp_type) :: sp_type
contains
procedure, pass(prec) :: setsv => sprecsetsv
procedure, pass(prec) :: setag => sprecsetag
procedure, pass(prec) :: cseti => m_scprecseti
procedure, pass(prec) :: csetr => m_scprecsetr
generic, public :: set => setsv, setag
end type sp_type

interface
subroutine sprecsetsv(prec,val,info)
import :: sp_type, sbs_type
class(sp_type), intent(inout) :: prec
class(sbs_type), intent(in) :: val
integer, intent(out) :: info
end subroutine sprecsetsv
subroutine sprecsetag(prec,val,info)
import :: sp_type, sba_type
class(sp_type), intent(inout) :: prec
class(sba_type), intent(in) :: val
integer, intent(out) :: info
end subroutine sprecsetag
subroutine m_scprecseti(prec,what,val,info)
import :: sp_type
class(sp_type), intent(inout) :: prec
character(len=*), intent(in) :: what
integer, intent(in) :: val
integer, intent(out) :: info
end subroutine m_scprecseti
subroutine m_scprecsetr(prec,what,val,info)
import :: sp_type
class(sp_type), intent(inout) :: prec
character(len=*), intent(in) :: what
real, intent(in) :: val
integer, intent(out) :: info
end subroutine m_scprecsetr
end interface

end module s_p_type

subroutine m_scprecseti(p,what,val,info)

use s_p_type, protect_name => m_scprecseti

implicit none

! Arguments
class(sp_type), intent(inout) :: p
character(len=*), intent(in) :: what
integer, intent(in) :: val
integer, intent(out) :: info


info = 0


end subroutine m_scprecseti

subroutine m_scprecsetr(p,what,val,info)
use s_p_type, protect_name => m_scprecsetr

implicit none
class(sp_type), intent(inout) :: p
character(len=*), intent(in) :: what
real, intent(in) :: val
integer, intent(out) :: info

info = 0

end subroutine m_scprecsetr

subroutine sprecsetag(p,val,info)

use s_p_type, protect_name => sprecsetag

implicit none
class(sp_type), intent(inout) :: p
class(sba_type), intent(in) :: val
integer, intent(out) :: info

info = 0

end subroutine sprecsetag
subroutine sprecsetsv(prec,val,info)
use s_p_type, protect_name => sprecsetsv

class(sp_type), intent(inout) :: prec
class(sbs_type), intent(in) :: val
integer, intent(out) :: info

info = 0
end subroutine sprecsetsv

program try
use s_p_type
type(sp_type) :: sprec
type(sba_type) :: s_ag
integer :: info

call sprec%set('Foo',1,info)
call sprec%set('Bar',1.0,info)
call sprec%set(s_ag,info)

end program try

FortranFan

unread,
Feb 11, 2021, 11:32:38 AM2/11/21
to
On Thursday, February 11, 2021 at 10:10:45 AM UTC-5, sfilippone wrote:

> .. it compiles cleanly with GNU fortran but fails with Intel.
>
> Any comments? ..

@sfilippone,

For whatever it's worth, I think the code conforms to the Fortran standard. I think Intel compiler is wrong to issue the errors you show.

If you have support subscription with Intel, you may want to submit a support request with them.

Otherwise, you can try posting your case at their community forum and request someone from Intel support staff to take a look:
https://community.intel.com/t5/Intel-Fortran-Compiler/bd-p/fortran-compiler

You may also want to post this at the Fortran Discourse site if you're looking for wider Fortran community feedback before contacting Intel:
https://fortran-lang.discourse.group/
0 new messages