return false;
}
+ /* Some programmers can have a typo when using an implied-do loop to
+ initialize an array constant. For example,
+ INTEGER I,J
+ INTEGER, PARAMETER :: A(3) = [(I, I = 1, 3)] ! OK
+ INTEGER, PARAMETER :: B(3) = [(A(J), I = 1, 3)] ! Not OK, J undefined
+ This check catches the typo. */
+ if (sym->attr.dimension
+ && sym->value && sym->value->expr_type == EXPR_ARRAY
+ && !gfc_is_constant_expr (sym->value))
+ {
+ /* PR fortran/117070 argues a nonconstant proc pointer can appear in
+ the array constructor of a paramater. This seems inconsistant with
+ the concept of a parameter. TODO: Needs an interpretation. */
+ if (sym->value->ts.type == BT_DERIVED
+ && sym->value->ts.u.derived
+ && sym->value->ts.u.derived->attr.proc_pointer_comp)
+ return true;
+ gfc_error ("Expecting constant expression near %L", &sym->value->where);
+ return false;
+ }
+
return true;
}
character(3), parameter :: x(2) = ['abc', 'xyz']
character(2), parameter :: y(2) = [x(2)(2:3), x(n)(1:2)] ! { dg-error "CHARACTER length must be a constant" }
end
+! { dg-prune-output "Expecting constant expression" }
--- /dev/null
+! { dg-do compile }
+module m
+ integer :: i, j
+ integer, parameter :: a(3) = [1, 2, 3]
+ integer, parameter :: b(3) = [(a(j), i=1,3)] ! { dg-error "Expecting constant expression" }
+end
--- /dev/null
+! { dg-do compile }
+module m
+ implicit none
+ integer :: i, j
+ integer, parameter :: a(3) = [1, 2, 3]
+ integer, parameter :: c = a(j)
+ integer :: d = c ! { dg-error "initialization expression at" }
+end