| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test the fix for pr103312, in which the use of a component call in |
| 4 |
! initialization expressions, eg. character(this%size()), caused ICEs. |
| 5 |
! |
| 6 |
! Contributed by Arseny Solokha <[email protected]> |
| 7 |
! |
| 8 |
module example |
| 9 |
|
| 10 |
type, abstract :: foo |
| 11 |
integer :: i |
| 12 |
contains |
| 13 |
procedure(foo_size), deferred :: size |
| 14 |
procedure(foo_func), deferred :: func |
| 15 |
end type |
| 16 |
|
| 17 |
interface |
| 18 |
function foo_func (this) result (string) |
| 19 |
import :: foo |
| 20 |
class(foo) :: this |
| 21 |
character(this%size()) :: string |
| 22 |
end function |
| 23 |
pure integer function foo_size (this) |
| 24 |
import foo |
| 25 |
class(foo), intent(in) :: this |
| 26 |
end function |
| 27 |
end interface |
| 28 |
|
| 29 |
end module |
| 30 |
|
| 31 |
module extension |
| 32 |
use example |
| 33 |
implicit none |
| 34 |
type, extends(foo) :: bar |
| 35 |
contains |
| 36 |
procedure :: size |
| 37 |
procedure :: func |
| 38 |
end type |
| 39 |
|
| 40 |
contains |
| 41 |
pure integer function size (this) |
| 42 |
class(bar), intent(in) :: this |
| 43 |
size = this%i |
| 44 |
end function |
| 45 |
function func (this) result (string) |
| 46 |
class(bar) :: this |
| 47 |
character(this%size()) :: string |
| 48 |
string = repeat ("x", len (string)) |
| 49 |
end function |
| 50 |
|
| 51 |
end module |
| 52 |
|
| 53 |
module unextended |
| 54 |
implicit none |
| 55 |
type :: foobar |
| 56 |
integer :: i |
| 57 |
contains |
| 58 |
procedure :: size |
| 59 |
procedure :: func |
| 60 |
end type |
| 61 |
|
| 62 |
contains |
| 63 |
pure integer function size (this) |
| 64 |
class(foobar), intent(in) :: this |
| 65 |
size = this%i |
| 66 |
end function |
| 67 |
function func (this) result (string) |
| 68 |
class(foobar) :: this |
| 69 |
character(this%size()) :: string |
| 70 |
character(:), allocatable :: chr |
| 71 |
string = repeat ("y", len (string)) |
| 72 |
allocate (character(this%size()) :: chr) |
| 73 |
if (len (string) .ne. len (chr)) stop 1 |
| 74 |
end function |
| 75 |
|
| 76 |
end module |
| 77 |
|
| 78 |
use example |
| 79 |
use extension |
| 80 |
use unextended |
| 81 |
type(bar) :: a |
| 82 |
type(foobar) :: b |
| 83 |
a%i = 5 |
| 84 |
if (a%func() .ne. 'xxxxx') stop 2 |
| 85 |
b%i = 7 |
| 86 |
if (b%func() .ne. 'yyyyyyy') stop 3 |
| 87 |
end |