Fix compilation failure with C++98 compilers
[official-gcc.git] / gcc / testsuite / gfortran.dg / short_circuiting.f90
blob44ff7e43eeb50802fe545039a5fe3170fc7e3659
1 ! { dg-do compile }
2 ! { dg-additional-options "-Wextra" }
4 ! PR 85599: warn about short-circuiting of logical expressions for non-pure functions
6 ! Contributed by Janus Weil <janus@gcc.gnu.org>
8 module a
10 interface impl_pure_a
11 module procedure impl_pure_a1
12 end interface
14 contains
16 logical function impl_pure_a1()
17 impl_pure_a1 = .true.
18 end function
20 end module
23 program short_circuit
25 use a
27 logical :: flag
28 flag = .false.
29 flag = check() .and. flag
30 flag = flag .and. check() ! { dg-warning "might not be evaluated" }
31 flag = flag .and. pure_check()
32 flag = flag .and. impl_pure_1()
33 flag = flag .and. impl_pure_2()
34 flag = flag .and. impl_pure_a1()
35 flag = flag .and. impl_pure_a()
37 contains
39 logical function check()
40 integer, save :: i = 1
41 print *, "check", i
42 i = i + 1
43 check = .true.
44 end function
46 logical pure function pure_check()
47 pure_check = .true.
48 end function
50 logical function impl_pure_1()
51 impl_pure_1 = .true.
52 end function
54 logical function impl_pure_2()
55 impl_pure_2 = impl_pure_1()
56 end function
59 end