さまざまなコールバック関数をパラメーターとして受け取るジェネリック型にバインドされたプロシージャを作成しようとしています。次のコードをコンパイルすると(ifort 12.1.3を使用)、以下の警告が表示されます。
module test
type :: a_type
contains
procedure :: t_s => at_s
procedure :: t_d => at_d
generic :: t => t_s,t_d
end type a_type
abstract interface
integer function cb_s(arg)
real(4) :: arg
end function cb_s
integer function cb_d(arg)
real(8) :: arg
end function cb_d
end interface
contains
subroutine at_s(this,cb)
class(a_type) :: this
procedure(cb_s) :: cb
end subroutine
subroutine at_d(this,cb)
class(a_type) :: this
procedure(cb_d) :: cb
end subroutine
end module test
警告:
compileme.f(27): warning #8449: The type/rank/keyword signature for this specific
procedure matches another specific procedure that shares the same generic
binding name. [AT_D]
プロシージャの引数として使用する場合、コンパイラは異なる関数インターフェイスを区別していないようです...
私の質問は次のとおりです。これらの型がチェックされないのはなぜですか。また、引数としてプロシージャまたはプロシージャポインタを使用して、ジェネリック型にバインドされたプロシージャを作成するための正しいクリーンな方法は何ですか。
考えられる解決策
ウラジミールFが指摘したように、コールバック関数の戻り引数のみが型チェックされます。私の場合は、関数のインターフェイスを少し変更するだけで問題ありません。
abstract interface
real(4) function cb_s(arg)
real(4) :: arg
end function cb_s
real(8) function cb_d(arg)
real(8) :: arg
end function cb_d
end interface