Debian Codegraph @

gcc/testsuite/gfortran.dg/pr114874_2.f90

raw
1 ! { dg-do compile }
2 ! Test fix for regression caused by r14-9489 - invalid code.
3 ! Contributed by Harald Anlauf <[email protected]>
4
5 module q
6 type :: s
7 integer :: j
8 end type
9 type :: t
10 integer :: i
11 class(s), allocatable :: ca
12 end type
13 contains
14 subroutine foobar
15 class(*), allocatable :: c
16 c = t (1)
17 select type (c)
18 type is (t)
19 ! Regression caused ICE here in translation or error was missed - invalid array reference
20 if (c(1)%i .ne. 1) stop 5 ! { dg-error "Syntax error in IF-expression" }
21 if (allocated (c%ca)) then
22 ! Make sure that response is correct if problem is "nested".
23 select type (ca => c%ca)
24 type is (s)
25 ! Regression caused ICE here in translation or error was missed - invalid array reference
26 if (ca(1)%j .ne. 1) stop 6 ! { dg-error "Syntax error in IF-expression" }
27 end select
28 select type (ca(1) => c%ca) ! { dg-error "parse error in SELECT TYPE" }
29 type is (s) ! { dg-error "Unexpected TYPE IS statement" }
30 if (ca(1)%j .ne. 1) stop 6 ! { dg-error "nonderived-type variable" }
31 end select ! { dg-error " Expecting END IF statement" }
32 endif
33 end select
34
35 ! This problem was found in the course of the fix: Chunk taken from associate_64.f90,
36 ! the derived type and component names adapted and the invalid array reference added.
37 associate (var4 => bar4())
38 if (var4%i .ne. 84) stop 33
39 if (var4%ca%j .ne. 168) stop 34
40 select type (x => var4)
41 type is (t)
42 if (x(1)%i .ne. var4%i) stop 35 ! { dg-error "Invalid array reference" }
43 if (x%ca%j .ne. var4%ca%j) stop 36
44 class default
45 stop 37
46 end select
47 end associate
48 end
49 function bar4() result(res)
50 class(t), allocatable :: res
51 res = t(84, s(168))
52 end
53 end module q