1! REPEAT intrinsic -- various checks should be enforced
2!
3! { dg-do compile }
4program test
5  implicit none
6  character(len=0), parameter :: s0 = ""
7  character(len=1), parameter :: s1 = "a"
8  character(len=2), parameter :: s2 = "ab"
9  character(len=0) :: t0
10  character(len=1) :: t1
11  character(len=2) :: t2
12
13  t0 = "" ; t1 = "a" ; t2 = "ab"
14
15  ! Check for negative NCOPIES argument
16  print *, repeat(s0, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
17  print *, repeat(s1, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
18  print *, repeat(s2, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
19  print *, repeat(t0, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
20  print *, repeat(t1, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
21  print *, repeat(t2, -1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is negative" }
22
23  ! Check for too large NCOPIES argument and limit cases
24  print *, repeat(t0, huge(0))
25  print *, repeat(t1, huge(0))
26  print *, repeat(t2, huge(0)) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is too large " }
27  print *, repeat(s2, huge(0)) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is too large " }
28
29  print *, repeat(t0, huge(0)/2)
30  print *, repeat(t1, huge(0)/2)
31  print *, repeat(t2, huge(0)/2)
32
33  print *, repeat(t0, huge(0)/2+1)
34  print *, repeat(t1, huge(0)/2+1)
35  print *, repeat(t2, huge(0)/2+1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is too large " }
36  print *, repeat(s2, huge(0)/2+1) ! { dg-error "Argument NCOPIES of REPEAT intrinsic is too large " }
37
38end program test
39