While looking at some other PR, I found the urgent need for a rather
obvious improvement to compile-time diagnostics:
The KIND argument to intrinsics must be a compile-time constant.
Regtested on x86_64-pc-linux-gnu.
OK for master?
Thanks,
Harald
PR fortran/97408 - Diagnose non-constant KIND argument to intrinsics
The KIND argument to intrinsics must be a compile-time argument.
Improve check so that the proper diagnostics is emitted.
gcc/fortran/ChangeLog:
* check.c (kind_check): Enhance check for non-constant KIND
arguments.
gcc/testsuite/ChangeLog:
* gfortran.dg/kind_2.f90: New test.
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 1e64fab3401..fa795538a7c 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -646,7 +646,7 @@ kind_check (gfc_expr *k, int n, bt type)
if (!scalar_check (k, n))
return false;
- if (!gfc_check_init_expr (k))
+ if (!gfc_check_init_expr (k) || k->expr_type == EXPR_VARIABLE)
{
gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
diff --git a/gcc/testsuite/gfortran.dg/kind_2.f90 b/gcc/testsuite/gfortran.dg/kind_2.f90
new file mode 100644
index 00000000000..f3e5b7503ef
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/kind_2.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR97408 - Diagnose non-constant KIND argument to intrinsics
+
+program p
+ implicit none
+ integer :: i
+ integer, parameter :: lk(1) = [ 4 ]
+ print *, (int (1 , lk(i)), i=1,1) ! { dg-error "must be a constant" }
+ print *, (real (1 , lk(i)), i=1,1) ! { dg-error "must be a constant" }
+ print *, (cmplx (1, kind=lk(i)), i=1,1) ! { dg-error "must be a constant" }
+ print *, (logical (.true., lk(i)), i=1,1) ! { dg-error "must be a constant" }
+end