1! { dg-do compile }
2! { dg-options "-std=f2008" }
3
4! PR fortran/29785
5! PR fortran/45016
6! Check for pointer remapping compile-time errors.
7
8! Contributed by Daniel Kraft, d@domob.eu.
9
10PROGRAM main
11  IMPLICIT NONE
12  INTEGER, TARGET :: arr(12), basem(3, 4)
13  INTEGER, POINTER :: vec(:), mat(:, :)
14
15  ! Existence of reference elements.
16  vec(:) => arr ! { dg-error "Lower bound has to be present" }
17  vec(5:7:1) => arr ! { dg-error "Stride must not be present" }
18  mat(1:, 2:5) => arr ! { dg-error "Either all or none of the upper bounds" }
19  mat(2, 6) => arr ! { dg-error "Expected bounds specification" }
20
21  ! This is bound remapping not rank remapping!
22  mat(1:, 3:) => arr ! { dg-error "Different ranks" }
23
24  ! Invalid remapping target; for non-rank one we already check the F2008
25  ! error elsewhere.  Here, test that not-contiguous target is disallowed
26  ! with rank > 1.
27  mat(1:2, 1:3) => arr(1:12:2) ! This is ok, rank one target.
28  vec(1:8) => basem(1:3:2, :) ! { dg-error "rank 1 or simply contiguous" }
29
30  ! Target is smaller than pointer.
31  vec(1:20) => arr ! { dg-error "smaller than size of the pointer" }
32  vec(1:10) => arr(1:12:2) ! { dg-error "smaller than size of the pointer" }
33  vec(1:20) => basem(:, :) ! { dg-error "smaller than size of the pointer" }
34  mat(1:5, 1:5) => arr ! { dg-error "smaller than size of the pointer" }
35END PROGRAM main
36